Reputation: 28
I know it may seem easy, but I don't know where my program is lacking -
Everything mentioned is q9 (9.sql) of this -
https://cs50.harvard.edu/x/2020/psets/7/movies/
Details of the Question -
In 9.sql, write a SQL query to list the names of all people who starred in a movie released in 2004, ordered by birth year.
Your query should output a table with a single column for the name of each person.
People with the same birth year may be listed in any order.
No need to worry about people who have no birth year listed, so long as those who do have a birth year are listed in order.
If a person appeared in more than one movie in 2004, they should only appear in your results once.
And according to the website I should be getting only 18,013 rows. But if I run this, I get 21163 rows...
Can someone tell me what is wrong?
CODE :
SELECT people.name
FROM people JOIN stars
ON people.id = stars.person_id
WHERE stars.movie_id IN
(
SELECT DISTINCT movies.id
FROM movies
WHERE movies.year = 2004
)ORDER BY people.birth;
Upvotes: 0
Views: 876
Reputation: 6520
Here's the clue:
If a person appeared in more than one movie in 2004, they should only appear in your results once.
This sql is not adhering to that directive. David introduces the DISTINCT keyword around 33:43 of the lecture.
Upvotes: 1