Surendra Sharma

Surendra Sharma

Search This Blog

Thursday, January 30, 2014

Tech Tip on how to fix error Ambiguous column name 'Column Name' in SQL Server.

Suppose you have two tables TableA and TableB. Both these table contains ID column. Now if you are trying to access ID column as below

SELECT ID FROM TableA INNER JOIN TableB ON TableA.ID = TableB.ID 

You will get SQL error Ambiguous column name 'ID'.

Whenever you are using JOIN clause with more than one table and trying to access same field name from the table then you will get error Ambiguous column name 'ColumnName'.

How to fix it?

Solution:-

Always make sure to use table name as prefix with column name before accessing it as below

SELECT TableA.ID FROM TableA INNER JOIN TableB ON TableA.ID = TableB.ID 


Please leave your comments or share this tip if it’s useful for you.

No comments:

Post a Comment