UPDATE: I was able to easily and simply solve this problem by changing 2 things:
- Add to the end of the code:
AND people.name != "Kevin Bacon"
- Change nested query to movies.id instead of title.
Thanks to this thread for the answer: CS50 Pset 7 13.sql, I can't solve it, nested sqlite3 database
I'm at the very last step of PSET7 movies (https://cs50.harvard.edu/x/2020/psets/7/movies/) The goal output should be all people that have starred in a movie with Kevin, but Kevin himself should NOT be included.
I have a query that returns a list of all the names of people who starred in movies with Kevin Bacon, but Kevin is there. How can I remove him from the results easily? I've looked into NOT IN, but I can't figure out how to get that to work with nested queries the way I have set this up. So any advice is greatly appreciated.
Here's my code:
SELECT DISTINCT people.name
FROM people
INNER JOIN stars ON stars.person_id = people.id
INNER JOIN movies ON movies.id = stars.movie_id
WHERE movies.title IN (
SELECT DISTINCT movies.title
FROM movies
INNER JOIN stars ON stars.movie_id = movies.id
INNER JOIN people ON people.id = stars.person_id
WHERE people.name = "Kevin Bacon" AND people.birth = "1958");