Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Grouping, joining and cleaning up objectives challenge task 3 of 3 solution?

I have no clue what is wrong with my code. Can anybody help me with this? SELECT movies.title, IFNULL(AVG(score), 0) AS average FROM reviews LEFT OUTER JOIN movies ON movies.id = reviews.movie_id GROUP BY movie_id HAVING averages < 2;

3 Answers

Massimo Ross
Massimo Ross
11,982 Points

you need to switch the reviews table with movies table in the join statement. Also, you are missing part of the having condition.

My solution as follows select movies.title,IFNULL(avg(score),0) as average from movies left outer join reviews on movies.id=reviews.movie_id group by movie_id having average <2;

Maximiliane Quel
Maximiliane Quel
Courses Plus Student 55,489 Points


first you need to select from movies because you want to display the movies title. Consequently you need to perform a left outer join with the reviews table. You had that the other way round.

Then, I am not sure if I am jut not seeing you declare that the averages need to be under 2. It might be the formatting here. Average needs to be singular, then you add the operator and then the number.

Your statement should look like this:

SELECT movies.title,
       IFNULL(AVG(score),0) AS average
FROM movies 
ON movies.id = reviews.movie_id
GROUP BY movie_id 
HAVING average < 2;

Thanks everyone. It worked