I have 3 columns in my table
- status enum(‘Completed’,’Incomplete’,’In Progress’)
- severity enum(‘High’,’Low’,’Moderate’)
- created datetime
Now currently i am ordering by severity ASC created DESC status DESC. which is not working right. This is how i want it to be listed.
- Incomplete – High
- Incomplete – moderate
- Incomplete – low
- In Progress – High
- In Progress – moderate
- In Progress – low
- Completed – High
- Completed – moderate
- Completed – low
As well as Andomar’s solution, I’d consider having proper tables for status and severity. Not enums.
You can imply sort order from the key of these tables, but I’d probably have a “SortOrder” column for future use.Then you can JOIN the tables and order by the SortOrder.
No need repeat the CASE in every query that needs it
Edit: Simplifying Andomar’s idea…