Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Custom Order

I have a table that I select data from with a column called parent that's of unsigned integer type.

It has numbers from 0 to 12.

I want to select * from table order by parent asc, but with one exception: place the 0 at the end of the select so it would be like 1,2,3,4,5,6,7,8,9,0.

Is this possible with a single select in MySQL please?

like image 415
Francisc Avatar asked Nov 25 '25 16:11

Francisc


1 Answers

I would do something like this:

select * 
from your_table 
order by (parent != 0) desc, parent asc; 
like image 78
Ike Walker Avatar answered Nov 27 '25 08:11

Ike Walker