Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order By priority not alphabetically

I am trying to prioritize my query by the ticket_priority_id.

The IDs are categorized as ASAP, HIGH, MED, LOW.

When I order by ticket_priority_id it always puts it in alphabetical order (LOW is ahead of MED).

How can I make it so I can order by ticket_priority_id but not alphabetically but by importance. I want the order to go (from top to bottom) ASAP - HIGH - MED - LOW

like image 331
Booza Avatar asked Dec 11 '22 16:12

Booza


1 Answers

You can use a case statement in your order by like this

ORDER BY 
   CASE WHEN ticket_priority_id = 'ASAP' THEN 1
        WHEN ticket_priority_id = 'HIGH' THEN 2
        WHEN ticket_priority_id = 'MED' THEN 3
        WHEN ticket_priority_id = 'LOW' THEN 4
        ELSE 5
   END
like image 190
Lieven Keersmaekers Avatar answered Dec 21 '22 15:12

Lieven Keersmaekers