0

On the Pset page it says that the solution must have 3392 rows. I wrote two different solutions, both accepted by check50, with different number of rows.

The first one gives 3389 lines:

SELECT DISTINCT name FROM people
JOIN directors ON directors.person_id = people.id
JOIN movies ON movies.id  = directors.movie_id
JOIN ratings ON ratings.movie_id = movies.id
WHERE ratings.rating >= 9.0;

The second one gives 3392 lines:

SELECT name FROM people WHERE id IN
(SELECT person_id FROM directors WHERE MOVIE_ID IN
(SELECT movie_id FROM ratings WHERE rating >= 9.0));

Any idea on why they are both accepted and why they give different results?

1 Answer 1

1

There might be directors with same name/different person_id, which the first one handles doesn't handle well.

But I don't know why CS50 accepts the first query. Maybe it's because for the purpose of the query is just to select names and namesake doesn't matter much.

You must log in to answer this question.

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