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 trialNa Liu
2,753 PointsJOINing table challenge Task 1 of I, joining three tables??
The question is "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." And I think that it is just simple joining three tables together, but I am not aware where is wrong T.T
Na Liu
2,753 PointsThis is my code, and course link:https://teamtreehouse.com/library/integrating-php-with-databases/using-relational-tables/joining-tables
SELECT * FROM Media M JOIN Media_Genres MG ON M.media_id = MG.media_id JOIN Genres G ON M.genre_id = G.genre_id WHERE M.media_id=3;
1 Answer
Steven Parker
231,271 PointsThere's no genre_id column in the Media table.
So when joining the Genres table, you would reference MG.genre_id instead of M.genre_id.
That's the only error I see, but it doesn't seem to satisfy the challenge to fix it. Apparently the challenge wants to see this done without table aliases. So if you re-write the query using the table names instead of the aliases you should pass.
Na Liu
2,753 PointsYou are right! Thanks a lot!
Steven Parker
231,271 PointsSteven Parker
231,271 PointsTo enable a complete analysis, please show the code you are trying, and also provide a link to the course page.