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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![MUSTAFA DIRIK](https://secure.gravatar.com/avatar/a35bf143ba72ab3df3ce578eef8d4169?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
MUSTAFA DIRIK
15,023 PointsI need help with my code.
I need help with my code on this challenge: https://teamtreehouse.com/library/integrating-php-with-databases/using-relational-tables/joining-tables
this is my code and I didnt understand whats wrong with it..
SELECT * FROM Media JOIN Genres ON Media_Genres.genre_id = Genres.genre_id LEFT OUTER JOIN Media ON Media_Genres.media_id = Media.media_id WHERE Media_Genres.media_id=3;
1 Answer
![Ruud Claassen](https://secure.gravatar.com/avatar/da43bdcc45d3a702b12b896d5a0aa021?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ruud Claassen
9,359 PointsMake sure you build the query step by step:
- Start with the Media table
- Add the common table (Media_Genres) to be able to "connect" the right Genres to the Media item
- The Media_Genres table should be joined based on the Media_id
- Now the Media_Genres is connected, you can join the Genres table
- Genres.genre_id can be connected to the Media_Genres.genre_id
Ultimately you will end up with:
SELECT * FROM Media
JOIN Media_Genres ON Media_Genres.media_id = Media.media_id
JOIN Genres ON Genres.genre_id = Media_Genres.genre_id
WHERE Media.media_id = 3;
MUSTAFA DIRIK
15,023 PointsMUSTAFA DIRIK
15,023 PointsThank you soo much for your help.