The order of mysql ASC queries, starting at 1, then showing everything with a null value

I have an “order” column where I store articles and then display them in a specific order. I use enum type '0', '1', '2', '3' with 0 by default. I need a query to order the result as follows: 1, 2, 3, 0, 0, 0, 0, and so on with zeros. Is it possible?

+3
source share
2 answers

Try:

select * from table
order by val = '0', val

This will work even if you add new values ​​to the enumeration later.

+7
source

try it

select ...
from ...
order by case `order` when 0 then 4 else `order` end asc
0
source

All Articles