Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

There is something wrong with your query. Challenge Task 3 of 3

I'm on the third Task in the Grouping, Joining, and Cleaning Up Challenge.

I believe I've written everything accurately, but my JOIN may not be working correctly.

Hi Jami,

Can you post what you've tried if you're still stuck on this?

2 Answers

You're pretty close with that.

In this part:

ON reivews.movie_id = movies.reviews_id

You have a typo on reviews and the id in the movies table is id not reviews_id

The only other issue is the order that you have your tables around the LEFT OUTER JOIN

reviews LEFT OUTER JOIN movies

With a left join, the table you place on the left side will have all of its rows included but the table on the right will not necessarily have all of its rows included. With it set like this we will get all of the movies that have a review but we will be missing any movies from the movies table that never got a review.

In this case, we need to make sure we've included all the movies from the movies table whether they have a review or not.

I'm sorry I thought it attached my code

SELECT movies.title, IFNULL(AVG(score),0) AS "average" FROM reviews LEFT OUTER JOIN movies ON reivews.movie_id = movies.reviews_id GROUP BY movie_id HAVING average<2;