56

Instead of ASC or DESC, I want my query results to be in a specific, custom order.

For example, instead of A, B, C, D..., what if I wanted my results in, P, A, L, H...?

I have tried using case but not successfully

SELECT * FROM Customers
ORDER BY case country
when 'P' then 1 …

E.g., here, I'm trying to create a custom order on the Country column:

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
mhd noufel
  • 589
  • 1
  • 4
  • 5

1 Answers1

152
SELECT * FROM Customers
ORDER BY case when country = 'P' then 1
              when country = 'A' then 2
              when country = 'L' then 3
              when country = 'H' then 4
              else 5
         end asc
juergen d
  • 201,996
  • 37
  • 293
  • 362