Updating Column Based On Another Updated Column
My question has to do with the order of updates in a single update statement. I have observed that when I set variables using a SELECT statement, that the variables are set in orde
Solution 1:
The names on the right hand side of the assignment refer to the old values of the columns, regardless of the order they are in.
This (for example) allows you to swap two values without using a temporary variable.
UPDATE foo
SET a = b,
b = a
http://sqlfiddle.com/#!3/f6984/1
The SQL-92 specification (Section 13.10, General Rules, Item 6 on page 395) states:
- The
<value expression>s are effectively evaluated for each row of T before updating any row of T.
Post a Comment for "Updating Column Based On Another Updated Column"