简体   繁体   中英

Check if the sub-query includes all of the stated values

I'm trying to find movie_ids for movies that both johnny Depp and Helena Bonham Carted played in. I'm using SQLite3 as software and the famous IMDB dataset.

  • The result I got: ids for movies that either of them played

  • The Desired result: ids for movies that both of them played in

     select movie_id from stars where person_id in (select id from people where name in ("Johnny Depp", "Helena Bonham Carter"))

    );

SELECT s.movie_id
FROM stars s
INNER JOIN people p ON p.id = s.person_id
WHERE p.name in ('Johnny Depp', 'Helena Bonham Carter')
GROUP BY s.movie_id
HAVING COUNT(DISTINCT p.id) = 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM