title: Maintaining order in MySQL "IN" query
body: <p>I have the following table</p>
  
  <pre><code>DROP TABLE IF EXISTS `test`.`foo`;
  CREATE TABLE  `test`.`foo` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `name` varchar(45) NOT NULL,
    PRIMARY KEY  (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>Then I try to get records based on the primary key</p>
  
  <pre><code>SELECT * FROM foo f where f.id IN (2, 3, 1);
  </code></pre>
  
  <p>I then get the following result</p>
  
  <pre><code>+----+--------+
  | id | name   |
  +----+--------+
  |  1 | first  |
  |  2 | second |
  |  3 | third  |
  +----+--------+
  3 rows in set (0.00 sec)
  </code></pre>
  
  <p>As one can see, the result is ordered by id. What I'm trying to achieve is to get the results ordered in the sequence I'm providing in the query. Given this example it should return</p>
  
  <pre><code>+----+--------+
  | id | name   |
  +----+--------+
  |  2 | second |
  |  3 | third  |
  |  1 | first  |
  +----+--------+
  3 rows in set (0.00 sec)
  </code></pre>