devxlogo

Sorting SQL Results in Your Own Preferred Order

Sorting SQL Results in Your Own Preferred Order

USE PubS-- Sort Each of PubName in Natural Alphabetic Order but push A's to thelastselect * from publishersOrder by (CASE left(Pub_name,1) WHEN 'A' THEN 1000 ELSE ASCII(pub_name)END)--Sort Publishers By City in your own Order of Preference first and in anatural order for the--remaining cities. Also remaning cities to be sorted in the reverse alphaorderselect * from publishersOrder by (CASE CityWHEN 'Paris' 	THEN 1WHEN 'Chicago' 	THEN 2WHEN 'Boston' 	THEN 3WHEN 'New York' THEN 4WHEN 'Berkeley' THEN 5WHEN 'Dallas' 	THEN 6ELSE 100 END) ASC,City DESC
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist