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

General Discussion

Remi Williams
Remi Williams
4,004 Points

Database MySQL: 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 entered the following: SELECT * FROM movies INNER JOIN genres ON movies.title = genres.name;

I get the following error message: Bummer! You're not retrieving the movie 'title' first and the genre 'name' second. Use an INNER JOIN.

What am I missing here?

11 Answers

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hi Remi, So the first time I went through this I actually had to read the statement over and over again to make sense of exactly what it wants to see.

The challenge is asking you to SELECT specific columns FROM a table and INNER JOIN them to another table ON specific id matching a value. so basically the answer is:

SELECT movies.title, genres.name FROM movies INNER JOIN genres ON movies.genre_id = genres.id;

SELECT (title column from MOVIES) , (name column from GENRES) FROM (movies table) INNER JOIN (GENRES to the FROM table[MOVIES]) ON (match MOVIES table genre_id column WITH the value from the GENRES table ID column).

I hope I didnt make that TOO confusing. But that is how my brain interprets it. I am no expert on MySQL, someone else could probably break it down better than I just did. But that answer should work out for you.

the only thing that confuses me about this is that, if i'm not mistaken, you are selecting a column from the movies table (title) and a column from the genres table (name) but the code acts like both are being selected from the movies table (i.e. SELECT movies.title, genres.name FROM movies).. is this not saying that we are selecting a column name from the movies table that doesn't exist in that table?

What is the origin and purpose of the 'ON movies.genre_id = genres.id' Can someone explain this to me more clearly? Andrew is excellent but completely skipped this part.

Maria De Bruyn
Maria De Bruyn
4,635 Points

Great explanation and to the point. Very helpful for understanding the answer.

Remi Williams
Remi Williams
4,004 Points

Thanks Chris. Your explanation of how it works is spot on. I'm not too sure given the way the challenge is written that I would have came to the idea of using movies.genre_id and genres.id. The wording leads you to write it the way I wrote it that generates an error.

I was wondering why the seemingly extra column info was included. Now I know why. The challenge could stand to written differently. (AND I put this in the wrong box LOL)

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

This is what I keep putting in for the second question, but it keeps getting an error. What am I doing wrong. At least the data output below looks correct? UGH.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

So the challenge states:

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.

In the previous challenge you had something additional at the very ending that you are missing in this one. Your whole statement is correct but the last piece you are missing. Let me know if you figure it out. Trying to hint you without giving you the answer

the way this question is worded is very confusing... the grammar of that sentence doesn't make any sense to me.. his sentence structure is really confusing me

Ah, perfect. Thanks for the hint. I can't believe I didn't try that. Oh, well. It's always the last place you look. ;)

I am stuck on 2 of 2. It sounds like you are referencing it here. Im not sure what you mean.

the problem with the first question is that the question itself mentions nothing about actually using the 'genre_id'

Brad Halstead
Brad Halstead
5,662 Points

2nd answer.

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

Jeffery Watkins
Jeffery Watkins
17,326 Points

I got this to work by copying Chris's answer, but I did not learn anything from this challenge or video. Really poorly done.

This one was tough for me too. Read a few tutorials, the videos and tasks were a bit confusing.

Yeah... I struggled with this too. Luckily found this thread.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

I wouldn't say the challenge or video was "poorly" done. Anyone that has ever done MySQL statements never "got it" the first time. It does take practice because you basically need to visualize it while writing the statements on what you are actually trying to SELECT.

Imagine that your school teacher in Math class assigns you homework, but before leaving class the teacher hands each student the answer key to that homework after each day for the rest of the year. At the end of the year when you are expected to complete your Final exam without notes or an answer key, everyone that didn't study their work or research how numbers actually worked, will fail.

Having the answer given to you is useful for you to move on, but you learn nothing. If you will learn anything from coding it will be that Google is your best friend because everyone comes from a different background and there is no possible way that 1 instructor will give a one-answer fits all.

If you are completely confused after a video, the forums are kind of like your "in-class" questions where students like myself or staff can help you understand or give you a guiding hands to the right answer.