I am using DB2 for performing the below update operation.
update DATA set B_DESC=P_DESC, P_DESC=null
where B_DESC= *, P_DESC=*
(Select B_DESC,P_DESC from C_DATA)
The below is actually possible but since complex joins are involved in that sub query it is not advisable to use like below
update DATA set B_DESC=P_DESC, P_DESC=null
where B_DESC= (Select B_DESC from C_DATA), P_DESC=(Select P_DESC from C_DATA)
I have to update DATA table, but the B_DESC and P_DESC i have to fetch it from C_DATA table and use it in the UPDATE query.
Please let me know how to do it. It has to be a single query if possible.
Thanks in advance.
Does your 1st query not work? I'm not familiar with comma-separating parts of the
WHERE
clause (it's not valid on my version of DB2 - is it actually part of the syntax?).Normally, when I need to run these types of update queries, I use an
EXISTS
clause, like this:Use a merge query to update the table, instead of join. DB2 does not accept join in update query for that purpose, you have to use a merge: