mysql> select * from a where num is not null union select * from a where num is null;
+----+------+
| id | num |
+----+------+
| 1 | 4 |
| 2 | 9 |
| 4 | 20 |
| 5 | 25 |
| 3 | NULL |
+----+------+
5 rows in set (0.00 sec)mysql> select * from a where num is not null union select * from a where num is null order by num;
+----+------+
| id | num |
+----+------+
| 3 | NULL |
| 1 | 4 |
| 2 | 9 |
| 4 | 20 |
| 5 | 25 |
+----+------+
5 rows in set (0.00 sec)mysql> select * from a;
+----+------+
| id | num |
+----+------+
| 1 | 4 |
| 2 | 9 |
| 3 | NULL |
| 4 | 20 |
| 5 | 25 |
+----+------+
5 rows in set (0.00 sec)
+----+------+
| id | num |
+----+------+
| 1 | 4 |
| 2 | 9 |
| 4 | 20 |
| 5 | 25 |
| 3 | NULL |
+----+------+
5 rows in set (0.00 sec)mysql> select * from a where num is not null union select * from a where num is null order by num;
+----+------+
| id | num |
+----+------+
| 3 | NULL |
| 1 | 4 |
| 2 | 9 |
| 4 | 20 |
| 5 | 25 |
+----+------+
5 rows in set (0.00 sec)mysql> select * from a;
+----+------+
| id | num |
+----+------+
| 1 | 4 |
| 2 | 9 |
| 3 | NULL |
| 4 | 20 |
| 5 | 25 |
+----+------+
5 rows in set (0.00 sec)
from a
order by isnull(num) desc,num