I have a table that contains a bunch of values for various “trouble ticket” parts, most specifically one called “TicketStatus” and of course one called “DateCreated”. I am struggling to write a query that displays all my tickets in date descending order, but with the COMPLETED tickets listed after those with other status (new/pending/assigned/inprogress, etc).
If I ignore the TicketStatus then my query is:
SELECT * FROM tickets ORDER BY `DateCreated` DESC;
I could run two queries back to back and put them together afterwords:
SELECT * FROM tickets WHERE `TicketStatus`!= 'Completed' ORDER BY `DateCreated` DESC;
SELECT * FROM ticketsWHERE `TicketStatus`= 'Completed' ORDER BY `DateCreated` DESC;
But I am confident there is a way to do some magic in my ORDER BY clause to simply “sink” the “completed” ones to the bottom? I tried:
SELECT * FROM tickets ORDER BY `TicketStatus`='Completed', `DateCreated` DESC;
but that definitely does not work.
Thanks!
1