cs50 问题集 7 的 SQL 语句有什么问题?

What is wrong with this SQL statement for cs50 problem set 7?

这个说法有什么问题?结果没有输出。

select title from movies where id in 
(select movie_id from stars where person_id in 
(select id from people where name="Johnny Depp" intersect 
select id from people where name="Helena Bonham Carter"));

这条语句:

select id from people where name="Johnny Depp" 
intersect 
select id from people where name="Helena Bonham Carter"

returns common 2 个查询的结果,但是由于 id 是 table [= 的唯一主键13=] 没有任何情况会 return 任何东西。
更简单:如果第一个查询 returns 10 和第二个 returns 20 10 和 20 的交集不存在。
您可以通过连接获得所需的结果:

select distinct m.title
from movies m
inner join stars s1 on s1.movie_id = m.id 
inner join stars s2 on s2.movie_id = m.id 
inner join people p1 on p1.id = s1.person_id and p1.name = 'Johnny Depp'
inner join people p2 on p2.id = s2.person_id and p2.name = 'Helena Bonham Carter'