Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As indicated by <a href="https://stackoverflow.com/questions/14989008/do-update-statements-set-all-values-concurrently-at-the-same-time#comment21051031_14989008">Joe's SQL Fiddle comment</a>, it does indeed matter what order the column updates are performed. The MySQL documentation for <a href="http://dev.mysql.com/doc/refman/5.0/en/update.html" rel="nofollow noreferrer"><code>UPDATE</code></a> indicates this, stating that the expression for each column update will be evaluated in the order declared, and it always uses the "current" value of a column:</p> <blockquote> <p>If you access a column from the table to be updated in an expression, <code>UPDATE</code> uses the current value of the column. For example, the following statement sets <code>col1</code> to one more than its current value:</p> <pre><code>UPDATE t1 SET col1 = col1 + 1; </code></pre> <p>The second assignment in the following statement sets <code>col2</code> to the current (updated) <code>col1</code> value, not the original <code>col1</code> value. The result is that <code>col1</code> and <code>col2</code> have the same value. This behavior differs from standard SQL.</p> <pre><code>UPDATE t1 SET col1 = col1 + 1, col2 = col1; </code></pre> <p>Single-table UPDATE assignments are generally evaluated from left to right. For multiple-table updates, there is no guarantee that assignments are carried out in any particular order.</p> </blockquote> <p>So for <code>UPDATE var SET foo=foo+1, bar=foo+1</code>, <code>foo</code> will be set to <code>foo+1</code>, then the <code>bar</code> update will use the newly set value of <code>foo</code> in <code>foo+1</code>.</p> <p>It may also be worthwhile to note that this behavior differs from the SQL standard, which indicates that all column updates should conceptually happen "at the same time".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload