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.
Greg Kaleka39,019 Points
Here's a slightly more complex but more dynamic solution.
At the end of this video, Ben Deitch has a suggestion that you might want to return all rooms with the max capacity in case there is more than one. Rather than hard-coding in the number 40, you can use a subquery:
SELECT ID, CAPACITY FROM ROOMS WHERE CAPACITY = ( SELECT MAX(CAPACITY) FROM ROOMS );
Just thought I'd share
Steven Parker218,654 Points
You could also do this:
SELECT ID, MAX(CAPACITY) as CAPACITY FROM ROOMS
Here is my solution:
SELECT capacity FROM rooms ORDER BY capacity DESC LIMIT 1
Not only is this a better solution, it is the only correct solution. OK technically not the only one.... but the query shown in the video doesn't return the ID for the room with the largest capacity... it returns a random row then an unrelated field with the largest capacity.
Guilherme Mergulhao4,002 Points
SELECT * FROM ROOMS WHERE CAPACITY = (SELECT CAPACITY FROM ROOMS ORDER BY CAPACITY DESC LIMIT 1);
will work as well.
I use MySQL and MariaDB and I'm sure a significant portion of the teamtreehouse audience will as well. Consider this example (Run in the playground).
SELECT *, MAX(capacity), MIN(capacity) FROM rooms
I guess my thought is that, with this behavior, SQLite is in the minority. But I can' t find any references to back this up, so I could be wrong. Either way, with this being framed as an "SQL" class, the particular query in the video should not be recommended for this purpose.
Marcus GrantCourses Plus Student 2,546 Points
I am using T-SQL on Microsoft SQL Server Management Studio to run my queries. Another dynamic solution I came up with is:
SELECT TOP 1 * FROM ROOMS ORDER BY CAPACITY DESC;