title: Random unique Mysql Id
body: <p>I have a table and want to genarate random unique value to it using 1 mysql query.
  Table structure like:</p>
  
  <pre><code>id | unique_id
  1  | 1
  2  | 5
  3  | 2
  4  | 7
  </code></pre>
  
  <p>etc</p>
  
  <p>unique_id is integer(10) unsigned</p>
  
  <p>So I want to fullfill unique_id field with unique random value (not 1, 5, 2, 7 in my example) every time.</p>
  
  <p>Algorytm is:</p>
  
  <pre><code>1. Get 1 unique random value, which will not have duplicates in unique_id field
  2. Create new row with unique_id = result of 1 query
  </code></pre>
  
  <hr>
  
  <p>I tried</p>
  
  <pre><code>SELECT FLOOR(RAND() * 9) AS random_number 
  FROM table 
  HAVING random_number NOT IN (SELECT unique_id FROM table) 
  LIMIT 1
  </code></pre>
  
  <p>but it generates not unique values..</p>
  
  <p>Note: multiplier = 9 is given just for example, it is easy to reproduce this problem with such multiplier</p>