Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

Ranvir Sahota
Ranvir Sahota
9,844 Points

Column is specified but still ambiguous

I have resolved the issue however I fail to understand why the column was ambiguous. The problem with the code was I repeating the table that I was using for INNER JOIN in the FROM section. But why should this cause ModelName to be ambiguous.

SELECT Model.ModelName AS 'Model Name', Car.VIN, Car.StickerPrice AS 'Sticker Price' FROM Car, Model INNER JOIN Model ON Car.ModelID=Model.ModelID

1 Answer

Steven Parker
Steven Parker
216,148 Points

It becomes ambiguous when you have two of the same thing.

When you include the table the second time, you now have two columns with exactly the same name, so the database engine can't determine which one of the two you are asking for in your SELECT clause.

To resolve such an ambiguity, you would need to be able to distinguish the columns from each other. A table alias would be useful in such a case.

Ranvir Sahota
Ranvir Sahota
9,844 Points

Thanks for that and sorry for not making question clear the first time