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 trialMax Toth
3,777 PointsSubquery in the WHERE clause not detected?
When answering the challenge question and running the query below, I receive a message: "Bummer: The subquery should be in the WHERE clause." I admit it's not the most beautiful thing I've written, but there is indeed a subquery in the first WHERE clause. So a bit confused as to why this is failing?
SELECT m.ModelID, m.ModelName, AVG(c.StickerPrice) AS AvPr FROM Model AS m INNER JOIN Car AS c ON m.ModelID = c.ModelID WHERE c.StickerPrice IN (SELECT StickerPrice FROM Car WHERE StickerPrice > 30000) GROUP BY m.ModelID ORDER BY m.ModelID ;
1 Answer
Bramyn Payne
19,589 PointsI think you are over-complicating things here. I am assuming that you are stuck on task 1?
If so, start by breaking down what you need to do and solve each step.
Let's get all cars with a StickerPrice
greater than 30000 from the Car
table
SELECT * FROM Car WHERE StickerPrice > 30000;
Let's figure out how to connect the two tables (What columns do they share?), and return that column instead of everything.
SELECT ModelID FROM Car WHERE StickerPrice > 30000;
Next, we can write the query for ModelName
SELECT ModelName FROM Model WHERE ???;
Next, we can add the subquery in the WHERE
clause, using the shared column.
SELECT ModelName FROM Model WHERE ModelID IN (SELECT ModelID FROM Car WHERE StickerPrice > 30000);
I hope this helps!