can someone explain the difference between using IN and "="? Here is my code. When I use IN it runs perfectly but when I use "=" there is no output. Thank you!

SELECT title
FROM movies JOIN stars ON stars.movie_id = movies.id
JOIN people ON stars.person_id = people.id
WHERE (name = 'Johnny Depp' and movie_id IN (
    SELECT movie_id 
    FROM stars JOIN people ON people.id = stars.person_id
    where name = 'Helena Bonham Carter'))

The "Helena Bonham Carter" subquery returns a set of movie_id's. IN is the sql comparison operator to be used when comparing a single value to a result set of values.

  • Oh so IN is to compare one value to multiple values while "=" is to compare one value to one value? Just to clarify for my understanding.
    – anahop
    Jun 27 '20 at 6:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .