Forum Moderators: coopster
Sort with numbers first:
select *,0+someval from testme order by (0+someval)=0 asc,(0+someval)>0 asc;
+----+---------+-----------+
| id | someval | 0+someval |
+----+---------+-----------+
| 1 | 012abc | 12 |
| 3 | 30def | 30 |
| 5 | 12gkh | 12 |
| 2 | abc | 0 |
| 4 | def | 0 |
| 6 | rjk | 0 |
+----+---------+-----------+
Sort with the numbers last:
select *,0+someval from testme order by (0+someval)>0 asc, (0+someval)=0 asc;
+----+---------+-----------+
| id | someval | 0+someval |
+----+---------+-----------+
| 2 | abc | 0 |
| 4 | def | 0 |
| 6 | rjk | 0 |
| 1 | 012abc | 12 |
| 3 | 30def | 30 |
| 5 | 12gkh | 12 |
+----+---------+-----------+
Sort ignoring the numbers completely:
select *,0+someval from testme order by ((0+someval)>0 or (0+someval)=0) asc;
+----+---------+-----------+
| id | someval | 0+someval |
+----+---------+-----------+
| 1 | 012abc | 12 |
| 2 | abc | 0 |
| 3 | 30def | 30 |
| 4 | def | 0 |
| 5 | 12gkh | 12 |
| 6 | rjk | 0 |
+----+---------+-----------+