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 |
|
mariechristine
Starting Member
27 Posts |
Posted - 2006-08-16 : 08:19:03
|
| SELECT * FROM tblCountry WHERE Country_Id = 26 UNION ALL SELECT * FROM tblCountry WHERE Country_Id <> 26--order by country_Namei need to select country_id =26 and then the rest i want them ordered by name.if i put order by country_name, the country_id 26 isn't displayed as the first one.is there anyway to apply the order by only to the second select not the whole? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-16 : 08:42:08
|
| [code]SELECT *FROM tblCountryORDER BY CASE WHEN Country_ID = 26 THEN 0 ELSE 1 END, Country_Name[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-16 : 08:49:34
|
| [code]Select * From (Select Top 100 Percent *,Country_Name as CountryName From tblCountryWHERE Country_Id = 26Union All Select Top 100 Percent *,Country_Name From tblCountryWHERE Country_Id = 26 order by Country_Name ) as F [/code]Chirag |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-16 : 08:57:20
|
Chirag, change the last Country_Id = 26 to Country_Id <> 26. And after a clean-up this does the same thingSELECT f.Country_NameFROM ( SELECT Country_Name FROM tblCountry WHERE Country_ID = 26 UNION ALL SELECT TOP 100 PERCENT Country_Name FROM tblCountry WHERE Country_ID <> 26 ORDER BY Country_Name ) f But it still looks somewhat overworked... Peter LarssonHelsingborg, Sweden |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-16 : 09:00:47
|
quote: Originally posted by Peso Chirag, change the last Country_Id = 26 to Country_Id <> 26. And after a clean-up this does the same thingSELECT f.Country_NameFROM ( SELECT Country_Name FROM tblCountry WHERE Country_ID = 26 UNION ALL SELECT TOP 100 PERCENT Country_Name FROM tblCountry WHERE Country_ID <> 26 ORDER BY Country_Name ) f But it still looks somewhat overworked... Peter LarssonHelsingborg, Sweden
Opps Copy paste Chirag |
 |
|
|
|
|
|