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

Nelson Govea
PLUS
Nelson Govea
Courses Plus Student 1,951 Points

INNER JOIN DataBase

Continue to get an error:

Challenge Task 2 of 5

In a car database there is a Make table with columns, MakeID and MakeName, a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice.

For all cars in the database, show Make Name, Model Name, VIN and Sticker Price from the Model and Car tables in one result set.

Type in your command below.

Bummer! Your query didn't select the MakeName, ModelName, VIN and StickerPrice! SELECT MakeName, ModelName, VIN, StickerPrice FROM Car INNER JOIN Model ON Model.ModelD = Car.ModelID INNER JOIN Make ON Make.MakeID = Car.ModelID;

Steven Parker
Steven Parker
231,248 Points

Please provide a link to the challenge page to facilitate a complete analysis.

Duncan Kile
Duncan Kile
6,341 Points

Your JOIN most likely isn't working because you are joining the modelID to the makeID on your second join. You want to join a makeID to a makeID and/or a modelID to a modelID.

Also, you're asking the car table for things that aren't in that table, like makename and modelname. Those are in the other tables, so you need to let it know where by either using the form <alias>.<columnname> or <tablename>.<columnname> .

2 Answers

Steven Parker
Steven Parker
231,248 Points

Check your JOIN criteria.

Normally, you'll perform JOINs with ON columns that represent the same thing. This is what you have in the first JOIN using two ModelID columns.

But as Duncan suggested, you seem to have mismatched criteria in the second JOIN, using one MakeID and one ModelID. I suspect you are also looking at the wrong table for one of the terms. I'd guess you probably meant to write:

... ON  Make.MakeID = Model.MakeID

Many cars to 1 model and many models to 1 maker. You can't access the attribute MakeName without the Make table. Considering VIN, StickerPrice are only on the Car table, you need all 3 tables and 2 join statements to connect them. an Access command would look like:

SELECT MakeName, ModelName, VIN, StickerPrice FROM Make, Model, Car WHERE Model.MakeID=Make.MakeID AND Car.ModelID=Model.ModelID;