Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Ordering Results

Author  Topic 

newbie2006
Starting Member

7 Posts

Posted - 2007-07-25 : 12:00:01
I am trying to do a simple SQL query..the result will be sorted alphabetically by default, but i need to specify say, if there is a "Others" it will be placed last in the list. Is there any way to write the query using ORDER BY?

e.g
Australia
China
Others
USA

and i want it to be:
Australia
CHina
USA
OThers

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-25 : 12:02:03
SELECT Col1 FROM Table1
ORDER BY CASE WHEN Col1 = 'Others' THEN 1 ELSE 0 END, Col1



E 12°55'05.76"
N 56°04'39.42"
Go to Top of Page
   

- Advertisement -