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

George Michael
George Michael
1,783 Points

Syntax error near SELECT [Exercise]

https://teamtreehouse.com/library/integrating-php-with-databases/using-relational-tables/joining-tables

so i'm following this exercise and i have problem it says syntax error near SELECT but i don't understand why i know there is probably a problem near JOIN but i'm a bit lost ^^

George Michael
George Michael
1,783 Points

here is my code

SELECT media_id, title, category, img, format, year, category, genre FROM Media SELECT genre_id, genres FROM Genres JOIN Genres AND Media on Media.genre_id = Genre.genre_id WHERE media_id=3;

Simon Coates
Simon Coates
28,694 Points

i'm struggling with this stuff myself, but i think you list the all fields you want from the various tables (here it wants all hence the asterisk), then after the FROM you list your tables separated by the JOINs. A JOIN specifies the type of join and what the join is ON.

It may also give you trouble with ambiguous fields. When a field name appears on different tables, you may need to specify which table the field name is in reference to (media_id appears on two tables).

2 Answers

Simon Coates
Simon Coates
28,694 Points

it seems to accept

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
George Michael
George Michael
1,783 Points

Thanks a lot :) it's a bit difficult to imagine doing this stuff all by myself tough ^^