tags:

views:

15

answers:

1

I have two tables with same columns. i want to update table1 records whose status is 'Linked' by the corresponding values from table2.

table 1
ID              STATUS       VOUCHER
'T010000020 Not Linked      null
'T010000021 Linked          null
'T010000024 Not Linked      null
'T010000026 Linked          null

 table 2
 ID              STATUS       VOUCHER
'T010000020 Not Linked      null
'T010000021 Linked          11234
'T010000024 Not Linked      null
'T010000026 Linked          5423
+2  A: 
 UPDATE Table1 t1
   SET Voucher = (SELECT Voucher FROM
                  Table2 t2 WHERE t2.Id = t1.Id
                  and t2.Status = 'Linked')
 WHERE Status = 'Linked'
Michael Pakhantsov