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! While you're at it, check out some resources Treehouse students have shared here.

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

Databases

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
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

Hi,

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 
LEFT OUTER JOIN reviews 
ON movies.id = reviews.movie_id
GROUP BY movie_id 
HAVING average < 2;

Thanks everyone. It worked