Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Sep 9, 2003

Sorting SQL Results in Your Own Preferred Order


USE PubS
-- Sort Each of PubName in Natural Alphabetic Order but push A's to the
last
select * from publishers
Order 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 a
natural order for the
--remaining cities. Also remaning cities to be sorted in the reverse alpha
order
select * from publishers
Order by (CASE City
WHEN 'Paris' 	THEN 1
WHEN 'Chicago' 	THEN 2
WHEN 'Boston' 	THEN 3
WHEN 'New York' THEN 4
WHEN 'Berkeley' THEN 5
WHEN 'Dallas' 	THEN 6
ELSE 100 END) ASC,City DESC
Kapil Srivastava
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap