2

I'm not sure there is even a way to do this, but thought I would ask anyway.

I have the following example output from a query:

Name     Country   Number
--------------------------
Harry    Germany   2
Harry    UK        5
Harry    Portugal  6   
Zoe      Spain     10
Zoe      UK        5   

For the task in hand, we use the data for UK most often, and would therefore like this at the top of the results set. The data is grouped by name, and then split in to country and number, and it needs to be ordered by Name, and then Country (but with UK at the top of each grouping). The desired output would be:

Name     Country   Number
--------------------------
Harry    UK        5   
Harry    Germany   2    
Harry    Portugal  6   
Zoe      UK        5
Zoe      Spain     10

As you can see, UK is at the top of each grouping.

I would appreciate any advice, even if this cannot be done.

Thanks in advance

1 Answer 1

6

Use this syntax:

ORDER BY name,CASE WHEN country='UK' THEN 0 ELSE 1 END,country
1
  • So simple!! Thank you, this has been puzzling me for a while!
    – zatgolf
    Nov 5, 2013 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.