Gediminas Gediminas - 1 year ago 85
MySQL Question

Order by own `position` using sql

I have few hundreds items in table with

position is null
, I want to do an order by position and set
and etc, but also live the other results with same
position is null

the problem is, if I'm ordering
by order by position asc
, first results come where
position is null
and only after them comes results I want to be first. I what that these results with
would go in the end.

Is it possible to solve this only with sql?

Answer Source
select position
from YourTable
order by case 
when position is null 
then 1 else 0 end, position
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download