Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql query order ASC starting from 1 then show all with zero

Tags:

mysql

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

like image 700
Popescu Marian Avatar asked Feb 20 '23 20:02

Popescu Marian


1 Answers

Give this a try:

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

This will work even you add new values values to the enum later.

like image 149
Mosty Mostacho Avatar answered Mar 08 '23 01:03

Mosty Mostacho