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_NAME PROCESS_DT
-------------------------------------------------------
234 2 admin (null)
307 2 admin (null)
313 2 admin 11-11-2013
ORDER_ATTRIBUTE
ORDER_ID ATTRIBUTE_ID VALUE
-----------------------------------
234 123 ? --(ORDER_APPROVALS.CREATED_BY_NAME)
307 123 ? --(ORDER_APPROVALS.CREATED_BY_NAME)
I want to update value field against Attribute_ID 123. So far I tried following query. But that does not work. I have tried similar kind of join in Netezza and that works. Want to know, how to do it in DB2?
update ORDER_ATTRIBUTE OT set OT.VALUE =
(select CREATED_BY_NAME from ORDER_APPROVALS OA
where OA.ORDER_ID = OT.ORDER_ID and OA.PROCESS_DT is NULL)
where OT.ATTRIBUTE_ID = 123 and OT.ORDER_ID in
(select ORDER_ID from ORDER_APPROVALS where PROCESS_DT is NULL)