• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

SQL Group By

I have a sql statement which includes a field for the 'city' and I Group By the city.  It is possible to specify which city I want at the top of the list and then have the rest of the cities sorted below it?  Example:
101 E LEMON, TARPON SPRINGS
102 E LEMON, TARPON SPRINGS
101 E LEMON, CLEARWATER
102 E LEMON, CLEARWATER
101 E LMEON, ST PETERSBURG
As always, thanks!
0
MEINMEL
Asked:
MEINMEL
1 Solution
 
tim_csCommented:
You could do something like this...

ORDER BY
   CASE WHEN City = 'Tarpon Springs' THEN 1 ELSE 2 END,
   City
0
 
millsap_singerCommented:
Tim_cs's answer will work fine, but if you have a table for cities then it would be best to put the preferred sort order there.  

But if you want to sort the cities with the most addresses then you can put the ORDER BY COUNT(*) DESC at the end of your query.  Or whatever your aggregate function is.  

0
 
MEINMELAuthor Commented:
Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now