is it possible to increment the field a and b of a table (A.a and A.b) using the value c and d of a different table (B.c B.d) for all the row of A where A.x == B.z?
I'm getting crazy with this query
is it possible to increment the field a and b of a table (A.a and A.b) using the value c and d of a different table (B.c B.d) for all the row of A where A.x == B.z?
I'm getting crazy with this query
This one also works quite good
update TableA A set a = (select a from TableB B where A.x = B.z) where exists (select 1 from TableB B where A.x = B.z) ;
DB2 and the SQL standard don't have a FROM clause in an UPDATE statement. So you have to clearly separate the steps to
.
Here is an example:
To update two fields you may use an example like this:
The optimizer will see that the sub-queries in the SET and the FROM clause are identical and it should merge them in the internal execution plan.
Yes it is possible. You can try something like this:
You can read more about MERGE here.
Tested under DB2 10.6
Practically the same as @jhnwsk, but with added table short cuts.