title: mysql query execution time | reduce query
body: <p>I have a query which let me to change users order.</p>
  
  <p>here is my query:</p>
  
  <pre><code>  update test set orderID = 
        case orderID
          when (select orderID from ( select * from test where orderID &gt; ( select orderID from test where id = 'id I want to move up' ) limit 1) as nextOrderID ) then ( select orderID from ( select * from test where id = 'id I want to move up') as nextOrderID ) 
          when ( select orderID from ( select * from test where id = 'id I want to move up' ) as nextOrderID )  then (select orderID from ( select * from test where orderID &gt; ( select orderID from test where id = 'id I want to move up' ) limit 1) as nextOrderID )
        else
          orderID
        end 
  </code></pre>
  
  <p>I want to know if it won't took a lot of time to execute that query, and if it will , how to make it load faster, and is it possible to reduce that query?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>i edited the code a bit so now i think it will execute query faster..
  here is a part of code :</p>
  
  <pre><code>$query = "
   SELECT  (
      SELECT orderID 
      FROM test WHERE id = 'user id that i want to move up'
      ) AS user_order,
      (
      SELECT orderID 
      FROM test WHERE orderID &gt; user_order 
      ORDER BY orderID 
      LIMIT 0,1
      ) AS nextUser_order
   ";
   $result = mysql_query($query);
   $data = mysql_fetch_assoc($result);
   $query = "
   UPDATE test SET orderID = IF(orderID='{$data[nextUser_order]}', 
                    '{$data[user_order]}', '{$data[nextUser_order]}')
        WHERE orderID IN ('{$data[nextUser_order]}', '{$data[user_order]}');
     ";
   $result = mysql_query($query);
  </code></pre>