title: Reorder the whole MySQL table based on column values
body: <p>I have a MySQL table with about 17mn records with an <code>auto_increment</code> field. The structure is something like this:</p>
  
  <pre><code>+--------+-------------------+-----------+
  | ID     | Year1             |  Year2    |
  +--------+-------------------+-----------+
  | 1      | 2001              | 2         |
  | 2      | 2001              | 1         |
  | 3      | 1999              | 3         |
  | 4      | 2004              | 2         |
  +--------+-------------------+-----------+
  </code></pre>
  
  <p>I'd like to reorder the physical structure of the whole table by changing the <code>auto_increment</code> ID to match the <code>Year1</code> and <code>Year2</code> columns when ordered in ascending order. Something like this..</p>
  
  <pre><code>+--------+-------------------+-----------+
  | ID     | Year1             |  Year2    |
  +--------+-------------------+-----------+
  | 1      | 1999              | 3         |
  | 2      | 2001              | 1         |
  | 3      | 2001              | 2         |
  | 4      | 2004              | 2         |
  +--------+-------------------+-----------+
  </code></pre>
  
  <p>Is this possible with a query in MySQL or should I use PHP and loops, et al.?</p>
  
  <p><strong>Update</strong>
  The use case is this: The actual data I have is stored in a specific pattern. I wouldn't want the end user to identify the pattern (2001, then 2001, then 1999, etc).. Hence I'd like to rearrange the data in a standard, sorted fashion..</p>
  
  <p>There are no foreign keys for this table.</p>