0

I have table products with column price. It have rows with values:

2
0
4
5
0
3
1

What params with select should I use to get result like this:

1
2
3
4
5
0
0
zen
  • 980
  • 6
  • 18

3 Answers3

4

You could first order by 0 & then rest

SELECT * FROM <table> ORDER BY CASE WHEN price = 0 THEN 1 ELSE 0 END,price 
Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
3
select * from products
order by price = 0, price
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

Try it

SELECT *
FROM test
ORDER BY IF(price=0,999999999,price)

SQL Fiddle - http://sqlfiddle.com/#!9/98f02/2

Sergey Menshov
  • 3,856
  • 2
  • 8
  • 19