1

I'm trying to populate a column in Table A from the data in Table B based on a unique Identifier (only for matching records. I just started using MS SQL Server after using MySQL for 4 years. In MySQL, this would essentially be:

update TableA a
inner join TableB b
on a.IDColumn = b.IDColumn
set a.ColumnIWant = b.ColumnIWant

I've tried a number of different variations of this, but none of them work... Is the syntax that much different in MS SQL Server Management Studio? Can you use aliases? Any help would be greatly appreciated.

update TableA a
inner join TableB b
on a.IDColumn = b.IDColumn
set a.ColumnIWant = b.ColumnIWant
jarlh
  • 42,561
  • 8
  • 45
  • 63
Ian
  • 31
  • 1
  • 3

2 Answers2

1

You can't inner join directly to the update table. The syntax is

Update tableA
Set x = y
From tableA
Join tableB ...
Where ...
BlackICE
  • 8,816
  • 3
  • 53
  • 91
1
update a
set a.ColumnIWant = b.ColumIWant
from TableA a
inner join TableB b
on a.IDColumn = b.IDColumn
pkatsourakis
  • 1,024
  • 7
  • 20