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

Development Tools Database Foundations SQL Calculating, Aggregating and Other Functions Grouping, Joining and Cleaning Up

what am i missing here ?

What am i missing ?

It may be best to describe what it is that you're referring to. Could you post a code snippet, and describe the problem that you're having?

Task Like before, select the average "score" as "average", setting to 0 if null, by grouping the "movie_id" from the "reviews" table. Also, do an outer join on the "movies" table with its "id" column and display the movie "title" before the "average". Finally, include averages under 2.

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

Problem

I get a error saying something is wrong

3 Answers

Hi, Binu. You need to add title before IFNULL(AVG(score), 0) as it wants you to display the movie title before the average.

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

still doesnt work

Oh, you still want to group from the reviews table, so it should be ...FROM reviews LEFT OUTER JOIN movies ON....

sorry ryan , i'm not sure if i understand your suggestion completely ...

this is what i put it in : SELECT movies.title, IFNULL(avg(score),0) AS average FROM reviews LEFT OUTER JOIN movies ON reviews.movie_id = movies.id GROUP BY reviews.movie_id HAVING average < 2

error : you should try the SELECT statement

I see where it's wrong now. We need to do a RIGHT OUTER JOIN instead of a left. This should pass the challenge:

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

Thanks Ryan , this is working !

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