Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL Group By

Posted on 2011-09-21
3
195 Views
Last Modified: 2012-05-12
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
Comment
Question by:MEINMEL
3 Comments
 
LVL 15

Accepted Solution

by:
tim_cs earned 500 total points
ID: 36576710
You could do something like this...

ORDER BY
   CASE WHEN City = 'Tarpon Springs' THEN 1 ELSE 2 END,
   City
0
 
LVL 1

Expert Comment

by:millsap_singer
ID: 36581865
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
 

Author Closing Comment

by:MEINMEL
ID: 36583286
Thanks!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question