title: MySql get lowest row value and increase by 1 if row exist
body: <p>I have an order_id field which should contain unique value (0 or above). </p>
  
  <pre><code> $stmt = $db-&gt;prepare("SELECT MAX(order_id) AS order_id FROM media WHERE playlist_id=?");
   $stmt -&gt; bind_param("i", $playlist_id);
   $stmt -&gt; execute();
   $result = $stmt-&gt;get_result();
   $order = $result-&gt;fetch_assoc();
   $max_order_id = intval($order['order_id']);
  </code></pre>
  
  <p>I run this query before I insert new row and I get 0 returned on first row insert which works well. However next time I want to insert new row, it returns 0 as well in which case I want to increase this value by 1, by only if at least one row already exist. </p>
  
  <pre><code> $max_order_id+=1;
  </code></pre>
  
  <p>I could do this with 2 queries if I ask how many rows exist in another query. Is there a way to do this with one query?</p>