What does the error "Ambiguous column name 'id'" mean? I am getting an error with the following query that uses a right join.  My table has a column named 'id'.

SELECT TOP 6 id
FROM   dbo.tbldata
       RIGHT JOIN tblimg
               ON tbldata.id = tblimg.newsid
ORDER  BY createdDate DESC 


The error is:


  Ambiguous column name 'id'
The error is referring to "id" in the first line of your query.  SQL Server doesn't know whether you are referring to tbldata.id or tblimg.id.

It is good practice to always use an alias so that table schema changes are less likely to break your query:

SELECT TOP 6 td.id
FROM   dbo.tbldata td
       RIGHT JOIN tblimg ti
               ON td.id = ti.newsid
ORDER  BY createdDate DESC