Skip to content
Advertisement

update value only when value changed

I have to update main_table data from another table. Below is statement

We will have value in any one column among value_string,value_date in a row or for a key, based on type_key. (like if type_key is string then value_string will have value and value_date is null). There is a trigger which ensure this constraint.

even if there was no change in values of value_string or value_date, then updated_on will change. I want updated_on to be updated only if there is change in values. so i’m changing update query to below

Is there a better approach to rewrite above query to improve the performance of query ?

Advertisement

Answer

I would add a WHERE condition that only changes the row if at least one of the values is different.

alternatively you can write it as

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