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

Fredric von Stange
Fredric von Stange
3,867 Points

My SQL query using a derived table

SQL Reporting by Example > A Smelly Issue

I came up with a way to answer this problem using a derived table. Check it out:

SELECT COUNT(*) FROM SUBJECTS

  INNER JOIN (SELECT * FROM CLASSES WHERE PERIOD_ID = 1) AS PE_FIRST
    ON PE_FIRST.SUBJECT_ID = SUBJECTS.ID

  INNER JOIN SCHEDULE 
    ON SCHEDULE.CLASS_ID = PE_FIRST.ID

WHERE NAME LIKE "physical education";