How to update DB2 table with a join?

后端 未结 3 877
野的像风
野的像风 2021-01-16 13:59

I have two tables and I want to update by joining them. I am using DB2 V9.7.

ORDER_APPROVALS

ORDER_ID    CREATED_BY_ID   CREATED_BY         


        
3条回答
  •  情话喂你
    2021-01-16 14:50

    You are looking for the MERGE statement:

    merge into ORDER_ATTRIBUTE ot
        using (select ORDER_ID, CREATED_BY_NAME
                 from ORDER_APPROVALS
                where PROCESS_DT is null) oa
        on
           (ot.ORDER_ID = oa.ORDER_ID)
        when matched 
         and ot.ATTRIBUTE_ID = 123
        then update set VALUE = oa.CREATED_BY_NAME;
    

提交回复
热议问题