Im trying to find a list of all movies that that contain 2 or MORE cast members in them.
select title from Movie where movieID in(
select movieID
from Cast
join MovieHasCast
on Cast.castID = MovieHasCast.castID
where cast.name = 'gene wilder'
intersect
select movieID
from Cast
join MovieHasCast
on Cast.castID = MovieHasCast.castID
where cast.name = 'richard pryor')
my alternative would be something like this:
select title from Movie where movieID in(
select movieID
from Cast
join MovieHasCast
on Cast.castID = MovieHasCast.castID
where cast.name = 'gene wilder'
and movieID in (
select movieID
from Cast
join MovieHasCast
on Cast.castID = MovieHasCast.castID
where cast.name = 'richard pryor'))
This is just a sample of how I am accomplishing this. However, I am building this query dynamically in C# to filter a list of movies by genre, cast members, etc. I am concerned with performance.
Is this the best way to accomplish this task? I feel like there is a better way to do this I just don't know how especially since a User could select 10 cast members and that query would start to get really large - even though it would likely return 0 records.