I am looking to do an order by in a certain order. I know I can modify the entire database but I would then need to modify the entire code base.
What I am have, is a column in a table 'games' called 'status'.
So...
  SELECT * 
    FROM games 
ORDER BY status ASC  -- Will retrieve results going from 0 then 1 then 2
What I am looking for is to be able to order it by 1 then 0 then 2.
Any ideas???
If I understand correctly, using a CASE expression:
  SELECT g.* 
    FROM GAMES g
ORDER BY CASE g.status 
           WHEN 0 THEN 1
           WHEN 1 THEN 2
           WHEN 2 THEN 3
         END
Using FIND_IN_SET function:
  SELECT g.* 
    FROM GAMES g
ORDER BY FIND_IN_SET(g.status, '0,1,2')
Using FIELD function:
  SELECT g.* 
    FROM GAMES g
ORDER BY FIELD(g.status, 0, 1, 2)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With