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 trialRaymond Moore
Full Stack JavaScript Techdegree Student 11,174 PointsJoining Table HELP!
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.
SELECT * FROM Media WHERE media_id=3;
My Answer: SELECT * FROM Media JOIN Genres ON Media_Genres.genre_id = Genres.genres_id WHERE media_id = 3;
However, it continues to tell me my answer is incorrect and please try your code again. Could someone help me out here with a little understanding.
Thanks
3 Answers
Gabriel Plackey
11,064 PointsYou're missing the join onto media_genres like tomd said. Then you still will have the ambiguous column name on the where clause.
SELECT * FROM Media
JOIN Media_Genres ON Media.media_id = Media_Genres.media_id
JOIN Genres ON Media_Genres.genre_id = Genres.genres_id
WHERE Media.media_id = 3;
tomd
16,701 PointsThis might not be much help, but there are 3 tables. The media table, the genre table and the Media_Genre table. You are only joining 2 tables. You'll need to join the media table to the Media_Genre table and the genre table to the Media_Genre table.
Raymond Moore
Full Stack JavaScript Techdegree Student 11,174 PointsI thought about adding two joins, but was not for sure. Thank both of you very much. :)
Ray.