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

Ido Galili
Ido Galili
1,160 Points

Why do I recieve wrong answer if the results ar correct?

I wrote the correct quiry and keep recieving wrong answer. i counted the models and the result matches the data, I cant figure whats the problem.

Stuart Wright
Stuart Wright
41,119 Points

Can you post a link to the challenge and also include your code so we can check it please?

Ido Galili
Ido Galili
1,160 Points

Thanks! Link: https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries

Code: SELECT Model.ModelID, Model.ModelName, Car.StickerPrice FROM Model LEFT OUTER JOIN Car ON Model.ModelID = Car.ModelID WHERE Car.StickerPrice IN (SELECT Car.StickerPrice FROM Car WHERE Car.StickerPrice >= 30000);

3 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Ido

Bummer! The subquery doesn't return all ModelIDs for cars with the sticker price greater than 30000.

SELECT Car.StickerPrice FROM Car WHERE Car.StickerPrice >= 30000

Your subquery needs to return the ModelIDs, not the StickerPrice.

Also make sure you are selecting the correct columns in your query, you only need to select ModelName, and there's no need to perform a join in this question.

Stuart Wright
Stuart Wright
41,119 Points

You don't actually need to use a JOIN here, because the subquery does everything you need it to:

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

The code you posted will return duplicate values for model names because of the join, whereas the above code returns a list of unique model names.

Ido Galili
Ido Galili
1,160 Points

Thanks guys, Stuart I tried what you wrote but chose StickerPrice instead of ModelID.

Thanks for the important lesson.