SELECT * FROM atable ORDER BY display_order = 0, display_order
When display_order
is 0, the first sort member display_order = 0
evaluates to True
, otherwise it evaluates to False
. True
sorts after False
- so the first sorting criterion ensures that rows with display_order
of 0 are sorted at the end of the list.
The second term ORDER BY, display_order
, additionally defines the order of rows with nonzero order values.
Thus, two criteria give you the desired sort order.
source share