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

General Discussion

Joining Table and Aliasing Code Challenge 2 of 2

Hey everyone,

I am having a hard time getting this right. Here is the question.

Like before bring back the movie 'title' and genre 'name' but use the correct OUTER JOIN to bring back all movies regardless if the 'genre_id' is set or not.

This is my query.

SELECT movies.title AS movies_title, genres.name AS genre_name FROM movies LEFT OUTER JOIN genres ON movies.id= genres.id WHERE name IS NOT NULL;

This is the error I get.

Bummer! You're not retrieving the movie 'title' first and the genre 'name' second with all information from the 'movies' table. Use an OUTER JOIN. Use LEFT if the movies table is on the left or RIGHT if it's on the right of the statement.

PLEASE HELP!!!

4 Answers

Because you are doing an outer join, you will have all records from the movie table show up even if there is no genre id for them. Perhaps, the redundancy of the IS NOT NULL is the issue here.

Also, I can't recall - does it explicitly ask you to create an Alias for each column?

try this

SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id =genres.id;

This is the correct code for this problem by the way. All the others are a no go.

I did this:

SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id IS NOT NULL OR movies.genre_id IS NULL;

This worked fine for passing. Maybe leave out the aliasing unless the question explicitly asks for it.

... SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id;

Thank you Milos!