Get field value before updating
Is there a way to get the value before and update the request in the update request itself?
For example:
UPDATE t SET field1 = 'new', field2 = IF (field2 = field1, 'new', field2))
In 'field2 = field1' I want to check the previous field value. Mysql works in such a way that it updates field1 and then will compare with the new value, so it will always have the value "IF (field2 =" new ", ..."
So, I would like something like
UPDATE t SET field1 = 'new', field2 = IF (field2 = PREVIOUS_VALUE(field1), 'new', field2))
Updated:
swapping may not work sometimes in more complex examples when I want it to be like this:
UPDATE t SET field1 = IF (field1 = PREVIOUS_VALUE(field2), 'new', field1)), field2 = IF (field2 = PREVIOUS_VALUE(field1), 'new', field2))
+3
source to share