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 trialMikey Jay
6,402 PointsDatabase Foundations Joining Relational Data Between Tables in SQL Joining Tables and Aliasing Challenge
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 wrote:
SELECT movies.title, genres.name FROM movies INNER JOIN genres ON movies.title = genres.name;
Incorrect: Bummer! You're not retrieving the movie 'title' first and the genre 'name' second. Use an INNER JOIN.
What am I doing wrong?
5 Answers
hlias kantzos
19,191 Pointsyou use wrong key to match the two tables
Wendell Pulsipher
10,183 Pointsummm. hello?? you never answered me
Will Lam
7,027 PointsI'm bumping into the same roadblocks as Wendell here.. would appreciate if anyone could help shed some light.. thanks!
Devin Gray
39,261 PointsBasically you have to look at the question CAREFULLY, You have the first part right, joining the movies.title first and the genres.name second,
SELECT movies.title, genres.name FROM movies INNER JOIN
The next part is tricky, you're naming the wrong keys. Notice in the question that there are two different columns for each table, you have to replace the ON movies.title = genres.name
with the other columns listed that you're not trying to list first and second. I'm horrible at explaining and it was a struggle for me as well but I hope that helps.
Will Lam
7,027 PointsThanks Devin!~
Hunter MacDermut
15,865 PointsCorrect answer:
SELECT movies.title, genres.name FROM movies JOIN genres ON movies.genre_id = genres.id;
I had to read the entry on JOIN syntax from the W3C to wrap my head around this: http://www.w3schools.com/sql/sql_join.asp
First, select the "title" column from the movies table & the "name" column from the genres table:
SELECT movies.title, genres.name
Then, specify which two tables you're joining information from:
FROM movies JOIN genres
Lastly, and this one is tricky, you must select the columns from the tables that refer to one another:
ON movies.genre_id = genres.id;
Which means, "the genre_id column from the movies table refers to the id column in the genres table". That is, the number assigned to each movie as its "genre_id" corresponds to the same number in the genres table which is just called "id". The ON keyword lets you join the tables by specifying which columns from each table refer to one another.
Does that help? I find that even though I mostly understand it that it's still difficult to describe because, like most syntax, it's convoluted.
Devin Gray
39,261 PointsMuch better explanation than I could give, I knew that was the answer but I wasn't sure why. That explanation makes much more sense. I know it helped me.
Manish M
2,606 PointsThanks Hunter. http://www.w3schools.com/sql/sql_join.asp Pretty much help solving this puzzle. Its just third part which is tricky.
Wendell Pulsipher
10,183 PointsWendell Pulsipher
10,183 Pointsi don't understand.. which key is wrong here? i did the same thing I can't figure out which key is wrong?