mysql custom sorting first alpha then numeric using case when

Posted by Nizzy on Stack Overflow See other posts from Stack Overflow or by Nizzy
Published on 2010-06-03T20:51:29Z Indexed on 2010/06/03 20:54 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

How can you sort a query using ORDER BY CASE WHEN REGEXP? or other alternatives? I don't want to use UNION. Thank you

mysql> SELECT `floor_id`, `floor_number` FROM `floors`;
+----------+--------------+
| floor_id | floor_number |
+----------+--------------+
|        1 | 4            |
|        2 | 7            |
|        3 | G            |
|        4 | 19           |
|        5 | B            |
|        6 | 3            |
|        7 | A            |
+----------+--------------+


Expected result:
+----------+--------------+
| floor_id | floor_number |
+----------+--------------+
|        7 | A            |
|        5 | B            |
|        3 | G            |
|        6 | 3            |
|        1 | 4            |
|        2 | 7            |
|        4 | 19           |
+----------+--------------+

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sort