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

PHP

Having trouble with Subqureys

I'm having a hard time understanding what I'm supposed to do with the subquery to get it to show that right information cause right now it's telling me that I need to put in an IN for it to work.

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

I can't see the lesson, but from what you describe it should look something like this:

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

You can think of IN like phps' in_array but for SQL. The subquery will return a collection of the column selected then the outer query will select all rows that have the constraint in that collection.

Hope that helps.

-Ben

1 Answer

Thanks for the help Ben, I realized where I went wrong. Here's the answer that worked for me

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