I have a table that stores information about some events.
I would like to list these events, but I would like the upcoming events to be displayed first and in ascending order, and the latter to be displayed below in descending order.
I would like to do something like this:
(SELECT * FROM events WHERE date > NOW() ORDER BY date ASC) UNION (SELECT * FROM events WHERE date < NOW() ORDER BY date DESC)
I checked the MySQL doc and found out that UNION usually works with an unordered set of rows, so ordering with each of the SELECT is completely useless. None of UNION ALL seem to do the job.
After a short search, I know how to arrange the rows according to which SELECT created them, however I still don't know how to sort them by one column in a different order.
I think I could just do two SELECTs, one for upcoming events, one for the past. But I really wonder if it is possible to do this with just one request. Is there anything you could suggest?
source share