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

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

Relational Database Challenge Task 2 of 5: Bummer ambiguous column name Car.VIN

SELECT Make.MakeName, Model.ModelName, Car.VIN, Car.StickerPrice FROM Make INNER JOIN Model On Make.MakeID = Model.MakeID INNER JOIN Car ON Model.ModelID = Car.ModelID

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

It is as if there are two columns named VIN... though the "challenge" only states one...

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.

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

Bummer! SQL Error: ambiguous column name: Car.VIN

SELECT MakeName, ModelName, Car.VIN, StickerPrice FROM Make, Car INNER JOIN Model On Make.MakeID = Model.MakeID INNER JOIN Car ON Model.ModelID = Car.ModelID

SQL Error: ambiguous column name: Car.VIN

Sebastian Barbiero
Sebastian Barbiero
6,529 Points

Your code you are putting into the system and the code you have in the forum are two different things.

The code you posted in your initial question is correct.

The code you posted 6 minutes ago has a lot of errors.

First off you do not ID what table each column is coming from in your SELECT statement. That is your biggest issue. MakeName should be Make.MakeName like you have in your question post.

Also "FROM Make, Car INNER JOIN...." is incorrect. You start with selecting one table not two and then join each table after.

Using your code from your original post, without touching the meat of it and only the formatting, it should work.

SELECT Make.MakeName, Model.ModelName, Car.VIN, Car.StickerPrice FROM Make 
INNER JOIN Model ON Make.MakeID = Model.MakeID 
INNER JOIN Car ON Model.ModelID = Car.ModelID

If that doesn't work I have another suggestion for you.

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

Sebastian Barbiero I was trying to see if I would get "Ambiguous" on other statements, but it still only cared about Car.VIN... I am still not sure why..

Your response worked.

SELECT Make.MakeName, Model.ModelName, Car.VIN, Car.StickerPrice FROM Make INNER JOIN Model ON Make.MakeID = Model.MakeID INNER JOIN Car ON Model.ModelID = Car.ModelID

Sebastian Barbiero
Sebastian Barbiero
6,529 Points

I'm not sure I understand your question.

Glad the code worked.

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

I was trying to break the query to give another warning... to sanity check.. but was still getting the same warning.

(I am a QA Analyst {Manual Tester} [6 months into the field, coming form 7 years as IT tech support], and am trying to widen my tool set. Thanks for your help. This community is awesome)

3 Answers

Steven Parker
Steven Parker
231,271 Points

Code Challenges are not the best place to test SQL error responses.

The challenge uses a mixture of ways to test your responses and does not rely solely on the SQL engine to generate the messages it shows you.

If you really want to experiment with SQL error responses, use the playground. Or even better, use an actual installed instance of the SQL server that you will be using or actual projects.

Joel McCracken Jr
Joel McCracken Jr
3,142 Points

I wasn't initially trying to "test". I resorted to that when the internet failed me, and I couldn't see why my request was failing.

ace punzalan
ace punzalan
4,081 Points

SELECT Make.MakeName, Model.ModelName, Car.VIN, Car.StickerPrice FROM Make INNER JOIN Model ON Make.MakeID = Model.MakeID INNER JOIN Car ON Model.ModelID = Car.ModelID;

Teacher Russell
Teacher Russell
16,873 Points

Why does the challenge ask us to return from the model and car table specifically, when we can't?

Steven Parker
Steven Parker
231,271 Points

You should always start a fresh question instead of asking one as an "answer" to an old question to have the best chance of being seen by more students.

But I'm sure it is possible to complete the challenges. If you're having trouble with one, post your query code and a link to the course page in an new question.

Kevin Gates
Kevin Gates
15,053 Points

Here's an answer, utilizing what was taught recently, including giving an alias to the longer table names:

SELECT mk.MakeName, md.ModelName, c.VIN, C.StickerPrice
FROM Make AS mk
  INNER JOIN Model AS md
    ON mk.MakeID = md.MakeID
  INNER JOIN Car AS c
    ON md.ModelID = c.ModelID;