title: Sorting results using "ORDER BY CASE" not using primary index
body: <p>I'm trying to do a sorting using the following query:</p>
  
  <pre><code>SELECT * FROM client 
  ORDER BY 
  CASE $desired_colum_to_order
     WHEN 'id' then `id`
     WHEN 'name' then `name`
     ELSE `id`
  END
  ASC
  </code></pre>
  
  <p>The problem is that this query is ordering ID as a string column, but it is a <strong>Integer Primary Key</strong>.</p>
  
  <p>The results become in this order:
  <em>10, 11, 12, 13, 5, 6, 7, 8, 9</em></p>
  
  <p>If I do the following query, MySQL orders correctly:</p>
  
  <pre><code>SELECT * FROM client 
  ORDER BY 
  id
  ASC
  </code></pre>
  
  <p>Now the results become in correct order:
  5, 6, 7, 8, 9, 10, 11, 12, 13</p>
  
  <p>Could someone explain me why is MySQL ordering like this, if is the same column in both queries?</p>
  
  <p>Thanks in advance!</p>