TL;DR: You can use ORDER BY column1 DESC, column2 ASC ... in your code.

The other day I was trying to get a custom ordering in a list for an object:

  • order decreasing by UNREAD MESSAGES count and then
  • order ascending by DATE

Initially, I tried a GROUP BY, but I could not get it to do the ordering properly. Then I thought of composite keys (multiple rows, like ones used in statistics), but then I realised it'd be overkill for a small app.

Then, I found out that you can do per-column sorting in ORDER BY:

SELECT *
FROM applications
ORDER BY unreadCount DESC, publicationDate ASC;

Cool!

HTH,