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 trial

Databases

Kian Chakamian
Kian Chakamian
15,410 Points

SQL Subqueries Code Quiz

I have been stuck on part 1 for a long time I I do not know what is wrong. It keeps telling me I am not including all the correct models over 30000

Here is my code:

SELECT StickerPrice, ModelName FROM Model INNER JOIN Car ON Model.ModelId = Car.ModelID WHERE StickerPrice IN (SELECT StickerPrice FROM Car WHERE StickerPrice > 30000)

1 Answer

Steven Parker
Steven Parker
229,657 Points

You wouldn't need to join the "Car" table and also create a subquery with it, and the subquery should probably return an ID of some sort instead of the price. You might also need to select * in the main query.

You probably don't need a join for this challenge at all. I could be more specific if you provide a link to the challenge itself.

Kian Chakamian
Kian Chakamian
15,410 Points

The Challenge is at Querying Relational Databases/ Subqueries / Subqueries

Steven Parker
Steven Parker
229,657 Points

With that info, I tracked the link down to this challenge.

My original suggestion is good, you can have your subquery return "ModelID" for the items with the right price and then test that in the WHERE clause. And now I'm sure that you won't need a JOIN.

But now I also see that the challenge asks you to "list all the Model Names ...", which means you also do not need to include the "StickerPrice" in the SELECT clause.

Kian Chakamian
Kian Chakamian
15,410 Points

I tried it again with your advice and it worked! Thanks a ton.