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 trialGeorge Stathoulias
Courses Plus Student 4,296 PointsTask 2 of 3
Here's my query: SELECT title FROM Media JOIN People ON Media.media_id = People.people_id LEFT OUTER JOIN Media_People ON Media.media_id = Media_People.media_id AND People.people_id = Media_People.people_id WHERE People.fullname LIKE '%Tolkien';
What is wrong??
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, George Stathoulias ! First, you need two INNER
joins. So you won't need LEFT OUTER JOIN
. You have some combination here where you're trying to do the media_id = people_id
from different tables. But the media_id
in one table should be equal to the media_id
recorded in the other table. The same thing goes for media_id
. The Media_People table is just a table with two columns. Each column has a list of integers. One column is for the people_id
and the other column is for the media_id
. Assuming the person was "Tom Hanks" and their people_id
was 3, I'm expecting that "Media_People" table to have quite a number of entries where the people_id
is 3 and each movie he's been in is recorded with its media_id
which then looks up the title of the movie in the Media table.
This was my solution:
SELECT title FROM Media
JOIN Media_People ON Media_People.media_id = Media.media_id
JOIN People ON People.people_id = Media_People.people_id
WHERE fullname LIKE '%Tolkien';
Note that the media_id in the joining table matches the media_id in the Media table and the person_id in the joining table matches the person_id in the Person table.
Hope this helps!
George Stathoulias
Courses Plus Student 4,296 PointsThank you Jennifer. You made things clear!