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

Vladimir Šoštarić
Vladimir Šoštarić
9,378 Points

Please tell me what I'm doing wrong in this query

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

1 Answer

Steven Parker
Steven Parker
231,261 Points

You didn't have any links, but I'm guessing this is from the Grouping, Joining and Cleaning Up challenge of the Database Foundations course.

Your having clause appears to be missing a comparison, but I bet that's just because you didn't use a blockquote around your SQL. You probably wrote this:

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

That's perfectly good SQL, and it certainly seems like it meets the criteria they asked for. But what they didn't say was probably hinted at by having you put that IFNULL in there.

I guess they want to see the largest number of results, and since there are more movies in the movies table than there are in the reviews table...

:point_right: Try using a RIGHT outer join.