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

Challenge 1. Using Subquery with IN Clause

Can someone please help with the following. I am having a brain freeze, cant think what to do. The answer is not correct. What do I need to do?

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

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

ModelName Impala Colorado Cherokee Cherokee Grand Cherokee Grand Cherokee Accord Camry Sienna Sienna Cherokee Accord

2 Answers

Steven Parker
Steven Parker
231,236 Points

Here's a few hints:

  • you don't need both a JOIN and a subquery
  • the common field you might use to join on could also be good for a WHERE clause
  • your subquery can return a column other than the one being used to filter results
Jackie Baxter
PLUS
Jackie Baxter
Courses Plus Student 2,801 Points

I went back and looked at the cheat sheet supplied within the subquery lesson to use for help with this challenge the following syntax example is from that cheat sheet SELECT <columns> FROM <table 1> AS <table 1 alias> INNER JOIN <table 2> AS <table 2 alias> ON <table 1 alias>.<column> = <table 2 alias>.<column>; This allowed me to see what Steven was saying above in that I did not need to use JOINS.