title: Select next 'free' integer based on input
body: <p>I have table which contains some data which (among other columns) has auto increment column "id" and one column called "sifra".</p>
  
  <p>I need to find next free number "sifra" based on some input (numbers).</p>
  
  <p>If I have following values in my table for column "sifra":</p>
  
  <ul>
  <li>1 </li>
  <li>2</li>
  <li>3 </li>
  <li>4 </li>
  <li>6</li>
  <li>11 </li>
  <li>12 </li>
  <li>14 </li>
  <li>322 </li>
  <li>323 </li>
  <li>324 </li>
  <li>678</li>
  <li>6790</li>
  <li>6810</li>
  <li>6812</li>
  </ul>
  
  <p>If I send value "1" mysql should return "10" because it's the next free integer with leading "1" and if i pass "32" it should return "320".</p>
  
  <p>If i pass "681" it should return "6811".</p>
  
  <p>This is what i've tried so far:</p>
  
  <pre><code> SELECT LEFT(MAX(a.sifra), 5) + 1 max_val
   FROM artikli as a
  left join artikli as arttab
  on a.sifra + 1 = arttab.sifra
  WHERE a.sifra LIKE '" &amp; sifra &amp; "%'
  </code></pre>