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
mahmoud saeed
14,071 PointsJoining 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
Luis Barahona
Courses Plus Student 2,432 PointsBecause 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?
Chris Collins
2,490 Pointstry this
SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id =genres.id;
Jordan Abu-Hamdeh
Courses Plus Student 4,379 PointsThis is the correct code for this problem by the way. All the others are a no go.
Chris Dziewa
17,781 PointsI 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.
Milos Rujevic
Full Stack JavaScript Techdegree Student 39,661 Points... SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id;
Tina Maddox
28,102 PointsThank you Milos!