Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SELECT returns error: 'Ambiguous column name '

Author  Topic 

cupeet987
Starting Member

11 Posts

Posted - 2007-12-27 : 10:14:40
The following two select statements look similar, except that in the second one I removed the column "abc" from the result set. I can't understand why does this error happens, how do I solve it and how do I get to return all three columns without error.


SELECT abc, def, ghi -- ERROR: Ambiguous column name 'abc'
FROM Table1, Table2, Table3
WHERE Table1.jkl = Table2.jkl
AND Table1.abc= Table3.abc


SELECT def, ghi -- runs!
FROM Table1, Table2, Table3
WHERE Table1.jkl = Table2.jkl
AND Table1.abc= Table3.abc


Thanks in advance for your precious time.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-12-27 : 10:21:48
table1.abc or table3.abc which one do you need?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

cupeet987
Starting Member

11 Posts

Posted - 2007-12-27 : 11:33:09
You gave-me the idea to solve it!
I used:
"SELECT Table1.abc, def, ghi"

Thank you, spirit1.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-28 : 01:37:04
and whenever you use select statement with joining two or more tables always make sure to qualify the table name for each column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -