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 trialJohn Fujita
1,776 PointsQuerying Relational Databases: Challenge Task 2 - Column headers don't appear - am I trippin?
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.
SELECT Make.MakeName AS 'Make Name', Model.ModelName AS 'Model Name', Car.VIN, Car.StickerPrice AS 'Sticker Price'
FROM Make
INNER JOIN Model ON Make.MakeID = Model.MakeID
INNER JOIN Car ON Car.ModelID = Model.MakeID;
BUMMER Your query didn't select the MakeName
, ModelName
, VIN
and StickerPrice
!
When I submit my answer it says that my query isn't selecting Make, Model, Vin etc. but I'm clearly selecting for them in my query and it looks like all the relevant information is showing up in the table EXCEPT for the column headers. We didn't have to do anything special for them to show up before, why aren't they there now? Or am I misinterpreting the error as something else?
Is this a bug?
I noticed that the headers didn't appear in Challenge 1, thought it was strange then too but it let me continue to the next question so I didn't think twice until now.
Help?
Thank you!
3 Answers
Remylus Losius
7,394 PointsIf you're able to see my table below, you'll see that the Car table doesn't have a MakeID foreign key. So, it's not plausible to create a relationship within the JOIN Car with MakeID -- Meaning that there's no equality (=).
YOUR QUERY
SELECT Make.MakeName AS 'Make Name', Model.ModelName AS 'Model Name', Car.VIN, Car.StickerPrice AS 'Sticker Price'
ROM Make
INNER JOIN Model
ON Make.MakeID = Model.MakeID
INNER JOIN Car
ON Car.ModelID = Model.MakeID;
So, in your last JOIN, I would do the following:
INNER JOIN Car
ON Model.ModelID = Car.ModelID;
Sample Tables
Make table
MakeID MakeName
---------------------------------
ID01 Honda
---------------------------------
IDo2 Ford
---------------------------------
Model table
ModelID MakeID ModelName
------------------------------------------------
MOD T ID01 Civic
------------------------------------------------
MOD Z IDo2 Focus
------------------------------------------------
Car table
CarID ModelID VIN ModelYear StickerPrice
--------------------------------------------------------------------
CAR01 MOD T VIN0203 2007 1,000
-------------------------------------------------------------------
CAR02 MOD Z VIN204 2010 1,500
------------------------------------------------------------------
Hope this helps.
Che Perth
1,989 PointsI found this one really difficult. The ModelID and MakeID threw me off.
Remylus Losius
7,394 PointsHi Che, Do you mean you understand it now?
Che Perth
1,989 PointsRemylus I got it. Thanks.
John Fujita
1,776 PointsJohn Fujita
1,776 PointsThanks! Makes sense now. I think just reading the columns off in a sentence was confusing me. Much easier to understand the schema when drawn out this way. I will start doing that myself
Thank you!