So i got this table:
+----+---------------------+-----+----------------+ | ID | WHEN | OFF | (other..stuff) | +----+---------------------+-----+----------------+ | 1 | 2012-09-17 17:00:00 | 0 | anything1 | | 2 | 2012-09-17 18:00:00 | 0 | anything2 | | 3 | 2012-08-31 21:00:00 | 1 | blabla321 | | 4 | 2012-08-31 18:30:00 | 1 | blab32121 | +----+---------------------+-----+----------------+
I want to select all keys but:
- Keys with off = 0 should be order by when ASC, and they should be
displayed first - Keys with off = 1 should be order by when DESC, and they should be
displayed after (at the end)
I tried something like this:
(SELECT * FROM `table` WHERE `off` = 0 ORDER BY `when` ASC)
UNION
(SELECT * FROM `table` WHERE `off` = 1 ORDER BY `when` DESC)
But it doesn’t work.
Also check:
https://i.stack.imgur.com/WWBEr.jpg
1 Answer