2010-10-14 13 views
10

Ho due tabelle con le stesse colonne. Voglio aggiornare i record di tabella1 il cui stato è 'Collegato' con i corrispondenti valori di tabella2.Query aggiornamento Oracle con selezionare

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 

risposta

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