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

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