How to update DB2 table with a join?

后端 未结 3 910
野的像风
野的像风 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:37

    I think you need to use a derived table to accomplish this:

    update order_attributes
    set value = (
      select
      created_by_name
      from(    
        select
        created_by_name,
        oa.order_id
        from
        order_approvals oa
        left outer join order_attributes ot
        on oa.order_id = ot.order_id
        AND OT.ATTRIBUTE_ID = 123 
        and OT.ORDER_ID in 
          (select ORDER_ID from ORDER_APPROVALS where PROCESS_DT is NULL)
        ) ORDERS
     WHERE orders.order_id = order_attributes.order_Id
        )
    

提交回复
热议问题