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 trialNoah Fields
13,985 PointsMy version of the answer with subqueries
Here's my version of the code, using subqueries.
-- Generate a schedule for Rex Rios.
SELECT NAME AS Class, PERIOD_ID AS Period FROM SCHEDULE
INNER JOIN (CLASSES) ON CLASSES.ID = CLASS_ID --Find classes where the class ID in classes = schedule ID
INNER JOIN SUBJECTS ON CLASSES.SUBJECT_ID = SUBJECTS.ID -- Join to subjects where the classes subject ID = Subject ID
WHERE STUDENT_ID IN (
SELECT ID FROM STUDENTS
WHERE FIRST_NAME = 'Rex' AND LAST_NAME = 'Rios' --But only for those where the schedule's ID colum matches Rex's ID
)
ORDER BY PERIOD_ID --Order by period for neatness
Chris Seals
4,507 PointsChris Seals
4,507 PointsThere are obviously several ways to go about this. Can any of the veterans chyme in about optimizing query structure for database performance. Specifically when making a table with many joins. should I be starting with the most limiting table and joining onto that, or can that be problematic? For example Here is what I wrote prior to watching the video: