The following is invalid syntax but it is what I’m trying to say essentially:
SELECT *
FROM categories
ORDER BY menu_order ASC WHERE parent = '1' || IF parent = '0' ORDER BY id ASC;
Is it possible to order the results of a select query differently based on a conditional within the query?
Just in case I wasn’t clear, I am trying to order the categories with a parent by menu order and those without a parent by id.
EDIT
So here’s how the database looks like:
id | name | parent | menu_order
==================================
1 | Apparel | 0 | 2
2 | Sports | 0 | 4
3 | Hats | 1 | 5
4 | Weights | 1 | 3
5 | Lights | 0 | 1
The result set of the query should be:
Apparel
Sports
Lights
Weights
Hats
use case in the order by, like this: