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.
Author |
Topic |
musclebreast
Yak Posting Veteran
77 Posts |
Posted - 2014-08-04 : 16:21:37
|
Hi,I have one table with one column:regionGlobalUSAEnglandGermanySpainWhat I want is that the first entry Global is always in the first row the rest should be ordered by alphabet. I tried this but order by works only for the result of union:SELECT * FROM csappcidb_region WHERE region='Global'UNION ALLSELECT * FROM csappcidb_region WHERE region<>'Global' ORDER BY region What else can I do?Best regards,Lara |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-08-04 : 16:26:33
|
select * from csappcidb_regionorder by case when region = 'Global' then 1 else case when region <> 'Global' then 2 end endTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-08-04 : 16:34:28
|
Alternativ:select * from csappcidb_region order by case when region='Global' then 0 else 1 end ,region |
|
|
musclebreast
Yak Posting Veteran
77 Posts |
Posted - 2014-08-04 : 16:39:29
|
Hi,thanks. The second option works...i didn't know that I can use case in a order by statement. This gives me many new options.:)Thnank you,Lara |
|
|
|
|
|