Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Using Relational Tables JOINing Tables

Raymond Moore
seal-mask
.a{fill-rule:evenodd;}techdegree
Raymond Moore
Front End Web Development Techdegree Student 11,153 Points

Joining Table HELP!

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;

My Answer: SELECT * FROM Media JOIN Genres ON Media_Genres.genre_id = Genres.genres_id WHERE media_id = 3;

However, it continues to tell me my answer is incorrect and please try your code again. Could someone help me out here with a little understanding.

Thanks

3 Answers

Gabriel Pierce-Lackey
Gabriel Pierce-Lackey
11,014 Points

You're missing the join onto media_genres like tomd said. Then you still will have the ambiguous column name on the where clause.

SELECT * FROM Media 
JOIN Media_Genres ON Media.media_id = Media_Genres.media_id 
JOIN Genres ON Media_Genres.genre_id = Genres.genres_id 
WHERE Media.media_id = 3;
tomd
tomd
16,701 Points

This might not be much help, but there are 3 tables. The media table, the genre table and the Media_Genre table. You are only joining 2 tables. You'll need to join the media table to the Media_Genre table and the genre table to the Media_Genre table.