title: MySQL - Save list order with single update
body: <p>Is it possible to sort a list and save the order in a single update?</p>
  
  <p>I tried this way:</p>
  
  <pre><code>UPDATE `jos_vm_category`,(SELECT @row:=0) AS init SET @row:=@row+1, list_order=@row ORDER BY `category_name` ASC
  </code></pre>
  
  <p>but got an error:</p>
  
  <blockquote>
    <p>1221 - Incorrect usage of UPDATE and
    ORDER BY</p>
  </blockquote>
  
  <p>If it's not clear, I need this:</p>
  
  <pre><code>category_id | category_name | list_order
      3       |       A       |       1
      1       |       B       |       2
      2       |       C       |       3
  </code></pre>
  
  <p>from this:</p>
  
  <pre><code>category_id | category_name | list_order
      1       |       B       |       1
      2       |       C       |       2
      3       |       A       |       3
  </code></pre>
  
  <p>with a single UPDATE.</p>
  
  <p>So list_order is a field of the table where I have to save the order of rows. (I already have the solution, but have to wait for 2 days, so I'll publish then if nobody answers the question.)</p>