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 Integrating PHP with Databases Using Relational Tables JOINing Tables

Erin DeSpain
Erin DeSpain
6,763 Points

Bad SQL or Bad Question?

The error is completely useless (as it gives no clues how to rewrite the SQL query). Can someone help me understand why this is not an acceptable answer and provide useful hints to answer it.

In case the question / answer aren't automatically referenced:

QUESTION:

Challenge Task 1 of 1
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.
Type in your command below, then press Ctrl-Enter.

MY CODE

SELECT * 
FROM Media 
JOIN Media_Genre ON Media.media_id = Media_Genre.media_id
JOIN Genre ON Media_Genre.genre_id = Genre.genre_id
WHERE Media.media_id = 3
;

RESPONSE

Bummer: There's something wrong with your SQL statement. Please review your code and try again.

NOTE:

I've already attempted writing this as one long string (in case it is read/parsed that way by the answer "comparator")--no luck.

2 Answers

It is an easier fix than you may think. The tables are Media_Genres with an s and Genres with an s.

Erin DeSpain
Erin DeSpain
6,763 Points

This was fixed by using:

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

Both Media_Genres and Genres needed to be pluralized. Thx!