title: Select unexisting value from MySQL
body: <p>There is a table "tbl" with unique values ​​"val" from a certain range (eg, from 100 to 999).</p>
  
  <p>Need to choose the guaranteed value, which does not yet exist in the table without the aid of an additional table with all existing values ​​over the left association.</p>
  
  <p>For example.</p>
  
  <p>Helper table fill (whole range) with values from 1 to 9.</p>
  
  <p>Basic table structure:</p>
  
  <pre><code>CREATE TABLE `ranger` (
    `val` int(2) unsigned NOT NULL,
    UNIQUE KEY `val` (`val`)
  ) ENGINE=MyISAM;
  
  INSERT INTO `ranger` (`val`) VALUES (1), (2), (4), (5), (6), (7), (8);
  </code></pre>
  
  <p>To select a non-existent value from <code>ranger</code>:</p>
  
  <pre><code>SELECT 
      val
  FROM 
      ranger_helper
  WHERE 
      val NOT IN(SELECT val FROM ranger)
  ORDER BY 
      RAND() 
  LIMIT 
      1
  </code></pre>