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 SQL Reporting by Example Day 1: Joining Tables Subjects in the Big Room

György Varga
György Varga
19,198 Points

Wasn't the question: 'Which subjects are taught in the largest room?'

Hi!

Check out my solution for the task above:

SELECT subjects.name FROM subjects 
INNER JOIN classes ON subjects.id = classes.subject_id
INNER JOIN rooms ON classes.subject_id = rooms.id
WHERE rooms.id = (SELECT id FROM rooms WHERE rooms.capacity 
                   = (SELECT MAX(rooms.capacity) FROM rooms)) GROUP BY subjects.name;

I think this is the correct solution for this task. Can you please check it?

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey György!

Great job using a subquery to figure out the largest room (rather than hardcoding it like I did)! But you've got one of your joins wrong. On your 2nd join, you're joining a SUBJECT_ID to a ROOM_ID when you want to be doing ROOM_ID to ROOM_ID:

INNER JOIN rooms ON classes.room_id = rooms.id

Hope that helps!

György Varga
György Varga
19,198 Points

Ohh thank you! I meant to join that... I was carless.