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.

PHP

Database 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
Wojtek Murawski
9,830 Points

You 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;

Thanks 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?

Thanks Wojtek, that did work!

Wojtek Murawski
Wojtek Murawski
9,830 Points

If 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 :)