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 trialHarm Muizer
3,476 PointsSQL excersice bummering.... You need to specify tables ON the JOIN
Excersice: We will be writing ONLY the SQL query for this challenge.
The library database contains a Media table with the columns media_id, title, img, format, year and category. It also contains a Genres table with the columns genre_id and genre. To join these tables, there is a Media_Genres table that contains the column media_id and genre_id
Add to the following SELECT statement to JOIN the Media table and the Genres table using the joining table Media_Genres.
NOTE: You will need to add the table to the WHERE clause so that the media_id column is not ambiguous.
Since table Media has a genre_id column (which by the way is not mentioned in the description) so
SELECT *
FROM Media
JOIN Genres ON Media.genre_id = Genres.genre_id
WHERE Media.media_id = 1
should do the job, but that is not the exercise.
so is should JOIN Media table with Media_Genres table ON the media_id to get the Media_Genres.genre_id to then JOIN Genres table on genre_id so we can retrieve the genre.
I'm getting nowhere after +/- 30 minutes of tying several possibilities i only get errors.
Select *
From Media
JOIN Media_Genres ON Media_Genres.genre_id = Media.genre_id
JOIN Genres ON Genres.genre_id = Media.genre_id
Where Media.media_id = 1
bummer: You need to specify tables ON the JOIN
or
Select *
From Media
JOIN Media_Genres ON Media_Genres.genre_id = Media.genre_id
JOIN Genres ON Genres.media_id = Media.media_id
Where Media.media_id = 1
bummer: You need to specify tables ON the JOIN
4 Answers
jcorum
71,830 PointsOK, not sure where you got the WHERE Media.media_id = 1 but this is what is needed instead:
SELECT * FROM Media
JOIN Media_Genres ON Media.media_id = Media_Genres.media_id
JOIN Genres ON Genres.genre_id = Media_Genres.genre_id
WHERE Media_Genres.media_id = Media.media_id
In the SQL DBMSs I've worked with the final WHERE clause would be redundant, so I'm not sure why they require it. But anyway, this version works!
jcorum
71,830 PointsHarm, can you give me a link to the challenge?
Select * From Media
JOIN Media_Genres ON Media_Genres.genre_id = Media.genre_id
JOIN Genres ON Genres.media_id = Media.media_id
WHERE Media.media_id = 1
The SQL looks OK, so there must be something else going on here.
Gerry Tarney
3,970 PointsHaving a similar problem. Continuing to get an ambiguous error even when specifying the table.
SELECT * FROM Media JOIN Media_Genres On Media_Genres.genre_id = Media.genre_id LEFT OUTER JOIN Media ON Media.genre_id = Genres.genre_id WHERE Media.media_id = 3;
SQL Error: ambiguous column name: main.Media.media_id
Harm Muizer
3,476 PointsHarm Muizer
3,476 PointsOk, that worked and i understand where i went wrong. Thanks for the help.