I have a DB that tracks movies and actors, with the following tables:
Person(ID, Name)
Movie(ID, Name)
Actors(ID, PersonID, MovieID)
ID fields are all primary keys and PersonID & MovieID are foreign keys.
I want to select all the movies that Tom Cruise and Brad Pitt played in. I tried to do the following:
SELECT * FROM Person, Actors
WHERE Person.ID = Actors.ActorID AND
(Person.Name= 'Tom Cruise' or Person.Name= 'Brad Pitt')
GROUP BY Actors.MovieID
HAVING COUNT(Actors.MovieID) > 1
This doesn't work, because the person name is not unique (and I can't change it to unique). If I have another actor named Brad Pitt and the two Brad Pitts played in the same movie it would return as a result too.
How can I do it?
NOTE: The number of actors I am querying about can change. I might need a movie with 10 actors that all played in it.