oracle - updating rows on table 1 based on data from table2 -


need query update columns of table1 based on field of table 2 if field of table 1 , table2 matches.

i want update id(1234 , 7891) of tbl 1 ids (4321 , 1987 respectively) of tbl2 if ids not same loc1 , loc2 same , upd y in tbl2.

     tbl1                                      tbl2  id   loc1    loc2                 id       loc1   loc2    upd 1234  a1     b1                   4321      a1     b1      y 4567  a2     b2                   4567      a2     b2 7891  a3     b3                   1987      a3     b3      y 3456  a4     b4                   6543      a4     b4    

try this

merge tbl1 e     using tbl2 h     on (e.loc1 = h.loc1 , e.loc2=h.loc2 , h.upd='y')   when matched     update set e.id = h.id; 

you can leave not matched clause.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -