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

PHP

Giovanni P.
Giovanni P.
4,803 Points

This Code Challenge has to be broken..

So I'm doing the code challenge where you first start using the JOIN keyword in Integrating PHP with Databases: https://teamtreehouse.com/library/integrating-php-with-databases/using-relational-tables/joining-tables

No matter what I do, no matter how much I specify which table media_id is from ( [TABLE].media_id ) it tells me media_id is ambiguous. I can't seem to figure out that problem.

But another problem that I can't fix is that while the instructions for the challenge tell me the Media_Genres tables contains the columns media_id and genre_id, I get the following: SQL Error: no such column: Media_Genres.media_id... I'm so lost by all of this. It's not making any sense.

When you get a moment can you link to the actual challenge you are doing? Thanks in advance!

Giovanni P.
Giovanni P.
4,803 Points

Oops sorry! I added it in at the top of the post.

1 Answer

Giovanni,

Sorry I haven't been on Treehouse in a few days. It took me a little bit of messing about to get this to work but it sems (at least my issue) stemmed from using aliases for the table names. Hopefully having gone through the videos you understand what is going on but as a quick rundown: We're selecting everything available, joining the Media_Genres table on a shared media_id, then joining the Genres based on a shared genres_id, and lastly filtering the results down to just records that have a media_id of 3.

SELECT *
FROM Media
JOIN Media_Genres
    ON Media_Genres.media_id = Media.media_id
JOIN Genres
    ON Media_Genres.genre_id = Genres.genre_id
WHERE Media.media_id = 3;