Reputation: 80385
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?
Upvotes: 3
Views: 1305
Reputation: 65527
I would do something like this:
select *
from your_table
order by (parent != 0) desc, parent asc;
Upvotes: 4
Reputation: 171371
select *
from table
order by case when parent is 0 then 1 else 0 end,
parent asc
Upvotes: 0