Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases SQL Reporting by Example Day 2: Advanced Selecting Student Schedule

My Code for this lesson using CTE

WITH classes_ids AS (SELECT CLASS_ID FROM SCHEDULE
JOIN STUDENTS ON SCHEDULE.STUDENT_ID = STUDENTS.ID WHERE STUDENTS.FIRST_NAME = "Rex" AND STUDENTS.LAST_NAME = "Rios")
SELECT classes_ids.CLASS_ID AS Class, PERIODS.ID AS PERIOD, PERIODS.START_TIME AS "START TIME", PERIODS.DURATION AS DURATION, ROOMS.ID AS ROOM, SUBJECTS.NAME AS SUBJECT

FROM classes_ids 
JOIN CLASSES ON classes_ids.CLASS_ID = CLASSES.ID
JOIN PERIODS ON CLASSES.PERIOD_ID = PERIODS.ID 
JOIN ROOMS ON CLASSES.ROOM_ID = ROOMS.ID
JOIN SUBJECTS ON CLASSES.SUBJECT_ID = SUBJECTS.ID
ORDER BY PERIODS.ID;