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 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.