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 trialJ J
15,775 PointsHelp with Challenege 1 of 4
SELECT Model.ModelID, ModelName, StickerPrice FROM Model INNER JOIN Car ON Model.ModelID = Car.ModelID WHERE Car.CarID IN(SELECT Car.CarID FROM Car WHERE StickerPrice > 30000);
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsHe is referring to this one:
https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries
I Cannot pass it as well, just like guy here:
https://teamtreehouse.com/community/bummer-as-answer-when-gives-correct-result-in-sql-playground
4 Answers
Joel Bardsley
31,249 PointsFor others accessing this question, it relates to the Code Challenge here: https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries
In a car database there is a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice.
Use a subquery along with IN to list all the Model Names with a Sticker Price greater than $30000
Firstly, you just need to list the Model Names:
SELECT ModelName FROM Model
As it's a subquery as part of an IN statement, you don't need to join the two tables. You can connect the ModelID columns for both the Model and Car tables as follows:
SELECT ModelName FROM Model
WHERE ModelID IN (
SELECT ModelID FROM Car
)
The WHERE clause contains the ModelID from the Model table and the subquery contains the ModelID from the Car table. Lastly you just need to filter the subquery by the StickerPrice:
SELECT ModelName FROM Model
WHERE ModelID IN (
SELECT ModelID FROM Car
WHERE StickerPrice > 30000
);
J J
15,775 PointsTHANK YOU!!! It was soo simple but it felt so complicated. Youre a Savior brother!
Denilson Velasquez
9,427 PointsIt's a play of words. I knew that the "Sticker price" would confuse people! Thanks for the answer.
Joel McCracken Jr
3,142 PointsThank you Other Joel =+)
I was over thinking this as well!!! And had not yet understood that they were ONLY wanting to see the ModelNames and not to also see the StickerPrice
Sean M
7,344 PointsSELECT ModelName FROM Model WHERE ModelID IN (SELECT ModelID FROM Car WHERE StickerPrice > 30000);
- Selecting the model name from the model table.
- specifying the model id from the car tables
- specifying even further the model id that has a sticker price greater than 30,000
Bernt Erik Engebretsen
5,377 PointsThank you very much for the correct answer!I am grateful! And Iยดve learnt something new as well. Many greetings from Bernt
A X
12,842 PointsA X
12,842 PointsWhat Challenge are you referring to? Is it the same one referenced here? https://teamtreehouse.com/community/bummer-as-answer-when-gives-correct-result-in-sql-playground
With databases, without knowing what your querying and why makes it impossible to help.