Tuesday, June 23, 2009

SQL Order By clause - List specific values on the top of list

List Specific values on the top in the order by clause

List all the coutries from counties table order by CountryName, but if you need to have "United States" and "Germany" on the top of list.

select * from Countries Order by
CASE Name
WHEN 'United States' THEN 1
WHEN 'Germany' THEN 2
ELSE 100
END,
Name

Puneet Singla

No comments: