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

Databases

Integrating with PHP (SQL Challenge).

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.

Everything was going swimmingly until I got to this part. It's not very clear to me. I see 3 tables. There is Media which has the following: media_id title img genre_id format year category 26 Mission: Impossible img/media/mission_impossible.jpg 1 DVD 1996 Movies

The Genre table is: genre_id genre 1 Action 2 Adventure 3 Comedy 4 Fantasy 5 Historical ...

Finally, we have Media_Genres which is media_id & genre_id. It is used to join the tables. I really dont see why the third table is needed for a join but I will push forward.

So Media table + Genres table = Media_Genres (merged data).

The question then has some example which I don't know what it's trying to communicate "SELECT * FROM Media WHERE media_id=3;" Show all columns from the Media table where the media id is 3. Ok?

So let's select all of the columns from media

SELECT * FROM Media (INNER) JOIN Genres ON Media.genre_id = Genre.genre_id

Note: INNER is optional and this 'glues both tables together using the shared 'genre id'. But uh oh, there is another table to utilize so I want to join again? So continuing from above I want:

(INNER) JOIN Media ON Media_Genres.media_id = Media.media_id

So almost done? What about this where clause? huh? So confused. Thanks.