Order by Numeric decimals then Alpha
Posted: Mon Aug 25, 2014 11:07 am
I am trying to get the decimal numbers to order correctly.
Here is my code:
$sql = "(SELECT * FROM locations WHERE X REGEXP '^[0-9]' ORDER BY cast(X as decimal), X, Y)
UNION ALL
(SELECT * FROM locations WHERE X REGEXP '^[a-z,A-Z]') ORDER BY X, Y";
Right now, numbers on top but not in correct order, Alpha on bottom is in order
1, 1.5, 10, 10.5, 18, 2, ADMIN, CAFE, CDC, CMAT
I need:
1, 1.5, 2, 10, 10.5, 18, ADMIN, CAFE, CDC, CMAT
Here is my code:
$sql = "(SELECT * FROM locations WHERE X REGEXP '^[0-9]' ORDER BY cast(X as decimal), X, Y)
UNION ALL
(SELECT * FROM locations WHERE X REGEXP '^[a-z,A-Z]') ORDER BY X, Y";
Right now, numbers on top but not in correct order, Alpha on bottom is in order
1, 1.5, 10, 10.5, 18, 2, ADMIN, CAFE, CDC, CMAT
I need:
1, 1.5, 2, 10, 10.5, 18, ADMIN, CAFE, CDC, CMAT