Could someone help me with how to approach fixing my SQL?
I am handling five tables.
The expected results are,
- "write a SQL query to list the titles of all movies in which both
Johnny Depp and Helena Bonham Carter starred"
- Your query should output a table with a single column for the title of each movie.
- You may assume that there is only one person in the database with the name Johnny Depp.
You may assume that there is only one person in the database with the name Helena Bonham Carter.
CREATE TABLE movies ( id INTEGER, title TEXT NOT NULL, year NUMERIC, PRIMARY KEY(id) ); CREATE TABLE stars ( movie_id INTEGER NOT NULL, person_id INTEGER NOT NULL, FOREIGN KEY(movie_id) REFERENCES movies(id), FOREIGN KEY(person_id) REFERENCES people(id) ); CREATE TABLE directors ( movie_id INTEGER NOT NULL, person_id INTEGER NOT NULL, FOREIGN KEY(movie_id) REFERENCES movies(id), FOREIGN KEY(person_id) REFERENCES people(id) ); CREATE TABLE ratings ( movie_id INTEGER NOT NULL, rating REAL NOT NULL, votes INTEGER NOT NULL, FOREIGN KEY(movie_id) REFERENCES movies(id) ); CREATE TABLE people ( id INTEGER, name TEXT NOT NULL, birth NUMERIC, PRIMARY KEY(id) );
This results in 59 rows, where it is supposed to be only 6 rows.
SELECT title FROM movies WHERE id IN (SELECT DISTINCT movie_id FROM
stars WHERE person_id = (SELECT id FROM people WHERE name IN
("Johnny Depp", "Helena Bonham Carter")));
I see other posts talking about using "WHERE IN" would be helpful, and I am indeed using it.