I have written the query for 6.sql but it does not work.

SELECT AVG(rating) FROM ratings
WHERE movie_id = (SELECT id FROM movies
WHERE year = 2012);

I can do this by using JOIN

SELECT AVG(rating) FROM ratings
JOIN movies ON movies.id = ratings.movie_id
WHERE year = 2012;

But still I want to know why nested query doesnot work.

1 Answer 1


Using IN instead of = solves the problem cause the movie_id is not one but too many

You must log in to answer this question.

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