Skip to content
Advertisement

Update in DB2 using where exists instead of join

I’m trying to perform an update in DB2, which I started out trying with an inner join, but DB2 won’t allow that. I altered it to use a ‘where exists’ clause but now it’s telling me that main_discount in my set clause is not found (I’m assuming because it isn’t referenced until the later where exists

How can I make this work as expected if I don’t yet have the column value I need?

Advertisement

Answer

DB2 for i does not allow the UPDATE table FROM that DB2LUW allows

You have two solutions

One is UPDATE using one subquery to select the rows to update, and another to get the value of main_discount

the other is MERGE

Maybe you should use DECFLOAT rather than FLOAT to avoid suprises

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement