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 trialAlfredo Prince
6,175 PointsI don't even know where to start. This wasn't really explained. Can anyone help me make sense of this?
I'm on the PHP Track and no one really went over JOIN
2 Answers
Scott Laughead
12,750 PointsCan you post the question?
jcorum
71,830 PointsAlfredo, you didn't give a link to the challenge so I can't test this, but maybe this is what they are looking for:
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
When you join two tables they must have at least one field in common (and of course, that field has to have the "same" data).
Here the Media table has a media_id field and the Media_Genres table has a media_id field, so the two tables can be joined.
The same is true for Media_Genres and Genres: they have media_id in common.
The net result is that this enables the query to show which media have which genres.
In "normal" SQL you wouldn't need the WHERE clause, but the editor insists.
Hope this helps.
Alfredo Prince
6,175 PointsAlfredo Prince
6,175 PointsYes here it is :)
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; NOTE: You will need to add the table to the WHERE clause so that the media_id column is not ambiguous.