Andromeda
Andromeda

Reputation: 12897

Oracle update query with select

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

Upvotes: 10

Views: 23792

Answers (1)

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25370

 UPDATE Table1 t1
   SET Voucher = (SELECT Voucher FROM
                  Table2 t2 WHERE t2.Id = t1.Id
                  and t2.Status = 'Linked')
 WHERE Status = 'Linked'

Upvotes: 15

Related Questions