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 trialJacinda Zhong
3,695 PointsDatabase MySQL: Joining Tables and Aliasing challenge
I am banging my head against a brick wall!!!!
Like before, bring back the movie 'title' and genre 'name' but use the correct OUTER JOIN to bring back all movies, regardless of whether the 'genre_id' is set or not.
I have absolutely no clue how I am supposed to query this, I've tried all of these: select movies.title, genres.name FROM movies OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id = 1 OR movies.genre_id = 0; select movies.title, genres.name FROM movies OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id = any_value; select movies.title, genres.name FROM movies OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id = 1; select movies.title, genres.name FROM movies OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id = 0;
Help!
3 Answers
Wojtek Murawski
9,830 PointsYou need to use LEFT OUTER JOIN, this should work: SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id;
Jacinda Zhong
3,695 PointsThanks Wojtek, that did work!
Wojtek Murawski
9,830 PointsIf I understood it correctly, the LEFT OUTER JOIN should pull all the data from movies and the joined data for both. There was a drawing of two interconnecting circles somewhere in the video explaining that. Hope that helps :)
Jacinda Zhong
3,695 PointsJacinda Zhong
3,695 PointsThanks Wojtek, that did work! Can you explain to me why it worked? Wouldn't left outer join just pull all data from the movies table?