Databases Querying Relational Databases Subqueries Subqueries

David Corrales
David Corrales
4,650 Points

Oh my gosh this stuff is getting tough! Subqueries are challenging anyone know how to solve this?

Challenge Task 1 of 4 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

Type in your command below, then press Ctrl-Enter.

Bummer: There's something wrong with your SQL statement. Please review your code and try again.

SELECT md.ModelName, ca.StickerPrice FROM Model AS md INNER JOIN Car AS ca ON md.ModelID = ca.ModelID WHERE StickerPrice IN (SELECT ca.StickerPrice FROM Car WHERE caStickerPrice> 30000);

3 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,287 Points
SELECT column FROM T1 WHERE ID IN (SELECT ID FROM T2 WHERE condition);
David Corrales
David Corrales
4,650 Points

It worked PERFECTLY! Who are you?! You should be famous! Coding genius!

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,287 Points

Some hints:

  • No need for the join since you will be using a subquery instead.

  • I would use a key in the subquery - the common field between the two tables.

  • You only need to select the ModelName in the main query

David Corrales
David Corrales
4,650 Points

Hmm, I'm still having a bit of a hard time, would you be able to provide an example of the correct way to do it perhaps?

David Corrales
David Corrales
4,650 Points

Wow you're literally so fast in the world! Thanks so much! I'll try it!