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.

Development Tools

Charles Kaelin
Charles Kaelin
4,003 Points

Code Challenge Question: Joining Relational Data Between Tables in SQL

I'm having difficulty finding a solution to this specific question:

"Code Challenge Question #2: 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."

I've attempted to answer this question in about 20 different ways, but have been unsuccessful in finding the correct solution.

Here is my best guess at solving the question: SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id WHERE movies.genre_id IS NOT NULL;

Again, I've tried modifying this offered solution about 20 different ways.

Any help would be highly appreciated.

Thanks, Charles

I could use some clarification on both challenge questions topics.

Specifically, the LEFT vs RIGHT OUTER JOIN, INNER JOIN, ON movies.genre_id = genres.id, and WHERE movies.genre_id IS NOT NULL parts.

The ideas are not clear to me yet. I will watch this video again.

Any clarification is appreciated.

2 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Charles Kaelin,

You're almost there! The question is asking you to return it if the id is set or not.

The LEFT OUTER JOIN will return all movies anyway. The WHERE movies.genre_id IS NOT NULL; isn't will only bring back movies that are set only. This is the equivalent of doing an INNER JOIN :)

Hope that helps!
Regards
Andrew

Charles Kaelin
Charles Kaelin
4,003 Points

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