4

I have 2 tables as :

TableA:

ID Value
1  A
2  B

TableB:

   Rank Value
    12   A
    13   B

I need to join both tables on Value column and update Value column of TableB with TableA's ID column. So result TableB will be:

Rank Value
12   1
13   2

I am using Sql Server 2008

Cannon
  • 2,725
  • 10
  • 45
  • 86

2 Answers2

2

Use update with join:

update b
set b.value = a.id
from tableb b 
  join tablea a on b.value = a.value
sgeddes
  • 62,311
  • 6
  • 61
  • 83
0

In SQL Server, you can do this with a join in the update. The specific syntax in your case is:

update b
    set value = a.id
    from tableb b join
         tablea a
         on b.value = a.value;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786