Databases Querying Relational Databases Subqueries Subqueries

Subquries

Using IN: 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 $3000

I don't get it.......

SELECT ModelName, ModelID, StickerPrice FROM Model AS md WHERE ModelID IN ( SELECT StickerPrice FROM Car AS cr WHERE StickerPrice > 30000);

2 Answers

Steven Parker
Steven Parker
195,578 Points

You're close, but I see two issues. First, the instructions only ask for Model Names in the final output.

Second, whatever you're tying to match with the membership operator (IN) must be present in the subquery:

WHERE ModelID IN ( SELECT StickerPrice --...
--    ^^^^^^^             ^^^^^^^^^^^^
--       these items need to match

I thought your answer was great! Helped my a lot.

Got it!

SELECT ModelName FROM Model AS md WHERE ModelID IN ( SELECT ModelID FROM Car AS cr WHERE StickerPrice > 30000);