I am trying to do a mysql sort that displays 0
first and then by the largest number.
My current mysql statement returns
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0
But I would like to get this
0, 0, 0, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
Is it possible to build a MySQL query that orders an integer from largest to smallest with 0
at the beginning?
Try this order by
statement:
order by val = 0 desc, val desc
The first part is a boolean that evaluates to "1" when the value is 1 and otherwise 0. The second orders the rest of the values in descending order.
you have to use 2 filters
select * from mytable
order by mycolumn=0 desc, mycolumn desc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With