title: MySQL order by after complex results
body: <p>I have these results in respons MySQL statement:</p>
  <pre><code>1   |    1
  2   |    1.1
  3   |    1.1.1
  4   |    2
  5   |    2.1
  6   |    2.1.1
  </code></pre>
  <p>I need to sort them the way that major digits are in <code>DESC</code> order and sub-results are in <code>ASC</code> order:</p>
  <pre><code>1   |    2
  2   |    2.1
  3   |    2.1.1
  2   |    1
  5   |    1.1
  6   |    1.1.1
  </code></pre>
  <p>Is there any <code>IF</code> conditions within <code>ORDER BY</code> ?</p>
  <p>Here's the query I used to sort the comments in 3 level hierarchy:</p>
  <pre><code>SELECT *, message_id AS SORT_KEY
  FROM forum_comment a
  WHERE replyToMsg = 0
  
  UNION ALL
  SELECT a.*, CONCAT(b.message_id, '.', a.message_id) AS SORT_KEY
  FROM forum_comment a, 
       forum_comment b
  WHERE b.replyToMsg = 0
        and b.message_id = a.replyToMsg
  
  UNION ALL
  SELECT a.*, CONCAT(c.message_id,'.', b.message_id,'.', a.message_id) AS SORT_KEY
  FROM forum_comment a,
       forum_comment b,
       forum_comment c
  WHERE c.replyToMsg = 0
    and b.message_id = a.replyToMsg
    and c.message_id = b.replyToMsg
  
  ORDER BY SORT_KEY
  </code></pre>