Question: Given database of the website "eMovies" that manage data about cinema movies. 

> 
> Write in SQL query that finds the names of movies that were filmed in 2002, 2003 or 2005, whose family name is "Ford" who played in those movies.
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/R8V1I.png)](https://i.stack.imgur.com/R8V1I.png)

The tables:

```
Actors 
    ActorID      PK
    Firstname 
    LastName

Directors 
    DirectorID   PK
    Firstname 
    LastName

Genres 
    GenreID      PK
    GenreDescr 

Movies 
    MovieID      PK
    MovieName 
    Year

ActorsMovies 
    MovieID      PK
    ActorID      PK 

DirectorsMovies 
    MovieID      PK
    DirectorID   PK 

GenresMovies 
    MovieID      PK
    GenreID      PK 

```

**My attempt:**

```
 SELECT Movies.MovieName
 FROM Movies,Actors,ActorsMovies
 WHERE Movies.Year=2002 OR Movies.Year=2003 OR Movies.Year=2005
 AND Actors.LastName = "Ford";

```

**The output:**

[![enter image description here](https://i.stack.imgur.com/v5t5E.png)](https://i.stack.imgur.com/v5t5E.png)

Answer: 
Join your tables.

```
SELECT m.MovieName
FROM Movies m
INNER JOIN ActorsMovies am ON m.movieID = am.movieID
INNER JOIN Actors a ON am.ActorID = a.ActorID
WHERE m.Year IN ('2002', '2003', '2005')
AND a.LastName = 'Ford';

```

If your looking for a more broad search on actor name use..

```
SELECT m.MovieName
FROM Movies m
INNER JOIN ActorsMovies am ON m.movieID = am.movieID
INNER JOIN Actors a ON am.ActorID = a.ActorID
WHERE m.Year IN ('2002', '2003', '2005')
AND (a.LastName = 'Ford' OR a.FirstName = 'Ford');

```

Or even broader..

```
SELECT m.MovieName
FROM Movies m
INNER JOIN ActorsMovies am ON m.movieID = am.movieID
INNER JOIN Actors a ON am.ActorID = a.ActorID
WHERE m.Year IN ('2002', '2003', '2005')
AND (a.LastName LIKE '%Ford%' OR a.FirstName LIKE '%Ford%');

```
```
SELECT Movies.MovieName
  FROM Movies,Actors,ActorsMovies
 WHERE Movies.MovieID = Actors.MovieID
   AND Actors.ActorID = ActorsMovies.ActorID
   AND Movies.Year in (2002,2003,2005)
   AND Actors.LastName = "Ford";

```

You didn't put any join's conditions so you got all the results.
In addition, use IN instead of or when comparing the same column to different results.
And last, dont use this joins, learn to proper syntax of an inner join, this will help you avoid those mistakes in the future.

```
select * from TABLE1 INNER JOIN TABLE2 on(table1.COLUMN = TABLE2.COLUMN)

```