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 Querying Multiple Tables with JOIN

jinhwa yoo
jinhwa yoo
10,042 Points

help me

I only understood "SELECT title, category,img, format, year , genre, publisher,isbn FROM Media..

next,,,,, when started "JOIN" I frustrated...

"SELECT title, category,img, format, year , genre, publisher,isbn FROM Media JOIN Genres ON Media.genre_id = Genres.genre_id LEFT OUTER JOIN Books ON Media.media_id = Books.media_id WHERE Media.media_id = $id"

Genres ON Media.genre_id = Genres.genre_id----------->what does this mean??????

1 Answer

Simon Coates
Simon Coates
28,694 Points

Your starting point should be foreign keys. These allow one-to-one or on-to-many relationships by having a column in one table reference a column in another table. (related topics: normalisation). As such a movie can have a field called genre_id with a value of 3, where there exists a Genre table where with a record with an id of 3, genre_name of 'Adventure'. The JOIN indicates to SQL which tables you want to join, and the ON expresses which fields to relate. (you need to understand this before you move one, as you will be delaying with junction object (tables that represent many-to-many relationships between other tables) which are more complex examples of the JOIN and ON techniques)