getting orderby query records except one particular record at last

Posted by nageshgatla7-20699 under Sql Server on 2/15/2013 | Points: 10 | Views : 1159 | Status : [Member] | Replies : 1
hi pls help

how to orderby query records except one particular record at last

am trying this but not working

select SubCategory_Name,Ranking from dbo.M_SubCategory where
CategoryID='82A2D4EE-B118-4F0F-AE26-332B286A34DF' and SubCategory_Name!='others' order by SubCategory_Name


UNION
select SubCategory_Name,Ranking from dbo.M_SubCategory where SubCategory_Name='others' and CategoryID='82A2D4EE-B118-4F0F-AE26-332B286A34DF'

please help.




Responses

Posted by: Sqldev on: 3/15/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

If I understand correctly, you want to fetch all your records in order except for CategoryID='82A2D4EE-B118-4F0F-AE26-332B286A34DF' .

If that is what your trying to query, then you may use the below code.

select SubCategory_Name,Ranking from dbo.M_SubCategory where 

CategoryID NOT in ('82A2D4EE-B118-4F0F-AE26-332B286A34DF')
order by SubCategory_Name



Hope this code will help you.

Best Regards,
SQL Blogger
http://learnsqltips.blogspot.com/
http://www.youtube.com/user/TheSSScreations




nageshgatla7-20699, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response