Screen Link:
https://app.dataquest.io/m/596/introduction-to-joins/7/aliasing-in-joins
My Code:
SELECT t.track_id, t.name AS track_name,
t.composer,
g.name AS genre
FROM track AS t
JOIN genre AS g
ON t.name = g.name;
What I expected to happen:
I am not quite sure I understand why genre_id is the more appropriate column to join the tables track and genre rather than the name column. I guess, what’s the reasoning behind making this choice? If you use the column “name” and keep the rest of the query intact, wouldn’t you get the desired output? If not, why? I thought that the column you join the tables on just has to be identical in each of the tables to do so. Right?
What actually happened: When I used the column “name” to join the tables, I received the output below:
The ON constraint did not join the table on the correct columns. Make sure it joins columns track.genre_id and genre.genre_id.