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 trialChris Gauthier
Courses Plus Student 6,434 PointsPHP Databases - Many to Many sql query
Can somebody help me clean up this query?
> select * from media where media_id=3 join on media.media_id = media_genres.media_id on genres.genre_id = media_genres.genre_id;
SQL Error: near "join": syntax error
Here is the link to the challenge Im working on:
Thanks in advance, Chris
2 Answers
Marc Busby
35,550 PointsHi Chris,
The WHERE clause needs to go after all the joining takes place. It should look something like:
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
Chris Gauthier
Courses Plus Student 6,434 PointsThank you, Marc!