title: How to shuffle a column in MySql
body: <p>After failing to find anything that matched my needs, I wrote this code to consistently shuffle the values of a column in mysql. Is there a better way to do this?</p>
  
  <pre><code>**Original table:**
  +----+-----------+
  | id | fname     |
  +----+-----------+
  |  1 | mike      |
  |  2 | ricky     |
  |  3 | jane      |
  |  4 | august    |
  |  6 | dave      |
  |  9 | Jérôme    |
  +----+-----------+
  
  **Possible output:**
  +----+-----------+
  | id | fname     |
  +----+-----------+
  |  1 | dave      |
  |  2 | jane      |
  |  3 | mike      |
  |  4 | ricky     |
  |  6 | Jérôme    |
  |  9 | august    |
  +----+-----------+
  
  DROP TEMPORARY TABLE IF EXISTS shuffle1;
  DROP TEMPORARY TABLE IF EXISTS shuffle2;
  CREATE TEMPORARY TABLE shuffle1 (id int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), original_values varchar(255), key original_values(original_values) );
  CREATE TEMPORARY TABLE shuffle2 (id int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), original_ids int(11), key original_ids(original_ids) );
  INSERT INTO shuffle1 (id, original_values) SELECT NULL, table1.fname FROM table1 ORDER BY rand();
  INSERT INTO shuffle2 (id, original_ids) SELECT NULL, table1.id FROM table1;
  UPDATE table1 SET table1.fname = (SELECT shuffle1.original_values FROM shuffle1 JOIN shuffle2 ON shuffle2.id = shuffle1.id WHERE table1.id = shuffle2.original_ids);
  </code></pre>