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

Unsure about how to complete JOINing tables exercise in Integrating PHP with Databases

For the answer that I entered below, I am unable to get this correct since I need to JOIN the Media_Genres table. I am not sure about how to do this. Any suggestions on how to resolve this issue?

> 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
media_id    title   img genre_id    format  year    category    media_id    genre_id    genre_id    genre
3   Refactoring: Improving the Design of Existing Code  img/media/refactoring.jpg   17  Hardcover   1999    Books   3   51  51  Business
3   Refactoring: Improving the Design of Existing Code  img/media/refactoring.jpg   17  Hardcover   1999    Books   3   17  17  Tech

2 Answers

There's definitely something wrong with this challenge.

You work looks fine to me (except I suggest you always capitalize keywords like SELECT, FROM, JOIN, ON, WHERE, ORDER BY, etc)!

Here's yours, which the editor rejects, with a spurious error message: "You need to JOIN the Media_Genres table".

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

Here's what I put in, which the editor accepts:

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

The editor also accepted this:

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

In short, if you do join instead of JOIN you are out of luck.

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

Challenge has been updated to allow for lowercase SQL keywords