-1

this is concerning SQL Server Management

I have been getting this error when trying to update a table: "Ambiguous column name 'Id'."

this is the query:

update DispatcherDB.dbo.Engineer
set MobilePhone = RestoreDB.dbo.W6ENGINEERS.MobilePhone
from DispatcherDB.dbo.Engineer join RestoreDB.dbo.W6ENGINEERS
on Id = W6Key

I have done this query before on other tables without a problem. I'm still a novice when it come to SQL, so any help/advice would be greatly appreciated! Thanks!

Stephen Sugumar
  • 545
  • 3
  • 9
  • 35
  • 1
    You need to tell the ON clause which Id column you mean (there is obviously one in both tables - and what a horrible name for a column anyway). Also please see [this](http://stackoverflow.com/questions/1604091/update-a-table-using-join-in-sql-server/1604212#1604212). – Aaron Bertrand Sep 25 '14 at 13:27
  • 1
    You have the `id` field in the tables you use in this update, you need to add either an alias or table name – neshkeev Sep 25 '14 at 13:27

1 Answers1

2

You have to give aliases to your tables (not really have to, but nice to do) and then you have to define of which table the id you are using in the on clause.

update E
set MobilePhone = W.MobilePhone
from DispatcherDB.dbo.Engineer E join RestoreDB.dbo.W6ENGINEERS W
on E.Id = W.W6Key
Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69