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 Database Foundations Joining Relational Data Between Tables in SQL Joining Tables and Aliasing

Joining Relational Data Between Tables in SQL

Quiz question 2 at the end of Stage 6, "Joining Relational Data Between Tables in SQL has me stumped. I seem to get a better result, though my answer is still not correct, if I use "movies" instead of "movie", and "genres" instead of "genre". Here are some of the things I have tried, and the results I have gotten.

SELECT movie.title, genre.name FROM movie LEFT OUTER JOIN genre ON genre.name; (returns) Bummer! There's something wrong with your SQL statement. Please review your code and try again.

(plus 11 variations and permutations of the above, all yielding the same result)

SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON genres.name; (returns) 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.

4 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Richard,

You need to join on the id column of the genre table and the genre_id column of the movies table.

SELECT g.name, m.title FROM movies m LEFT OUTER JOIN genres g ON m.genre_id = g.id

I hope this helps.

Yes, it did help. I feel like the function of the ON clause was not adequately explained in the course.

Justin can you explain the answer a bit more? Ive tried to do the same but it doesnt work (although in MYsql itslef it sort of works but then tells me that Aliens is a musical lol)

SELECT genres.name, movies.title FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genre_id;

I left out the 'm' and 'g' that you used in your example as I dont understand why they are being used and also they dont work too.

Adam Oliver
Adam Oliver
8,214 Points

Its very similar to the question 1 answer look-> SELECT movies.title, genres.name FROM movies LEFT OUTER JOIN genres ON movies.genre_id = genres.id;