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 trialsteven schwerin
7,722 Pointsdatabases
I'm not sure I'm understanding the concept of an INNER JOIN. I am working on a task asking me the following:
We have a 'movies' table with a 'title' and 'genre_id' column and a 'genres' table has an 'id' and 'name' column. Use an INNER JOIN to join the 'movies' and 'genres' tables together only selecting the movie 'title' first and the genre 'name' second.
I respond thus:
SELECT * FROM movies INNER JOIN genres ON movies.title = genres.name;
Can anyone help?
3 Answers
mcurrier
Courses Plus Student 3,190 PointsSELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name;
SELECT movies.title, genres.name FROM movies INNER JOIN genres ON movies.genre_id=genres.id;
Stephen Crockett
18,614 PointsM Currier has the right code in there. The difference is mostly in the ON ...
clause. You want to pick parts that will have the same value. The genre_id
column in that table was created specifically to correspond to an id
in the genres
table. So you want to join the tables ON the corresponding values.
SELECT movies.title, genres.name FROM movies INNER JOIN genres ON movies.genre_id=genres.id;
Michael Garcia
7,752 PointsI was having the same issue as Steven Schwerin, and I think what threw me off was the last statement on the question, (only selecting the movie 'title' first and the genre 'name' second.) After "ON" I was entering ( movies.title=genres.name ). I read it wrong, that statement meant to add ( movies.title, genres.name in front of SELECT ). Stephen Crockett statement is correct - "The genre_id column in that table was created specifically to correspond to an id in the genres table. So you want to join the tables ON the corresponding values".