E
E
Eugene2018-08-23 06:34:46
SQL
Eugene, 2018-08-23 06:34:46

How to sort SQL by price ranges?

Products are displayed on the site in accordance with some kind of sorting (by name, by priority, etc.)
You need to make sure that products with 0<price<1000000 are displayed at the beginning, and then with price=0 or >=1000000.
I understand how to do this with 2 queries, combining them into one result (UNION), but is it possible to somehow do this with one query using the standard SQL sorting mechanism?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-08-23
@eugeneledenev

ORDER BY (`price` = 0 OR `price` >= 1000000), `name`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question