By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,208 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,208 IT Pros & Developers. It's quick & easy.

Sql query for sorting the output in the descending order

P: 17
Select distinct b.contributor, blogaddress,count(b.contentid) RecipeCount,isnull(c.cnt,0) Other
from weblogs.dbo.blogentries b left outer join (select contributor , count(*) cnt from weblogs.dbo.blogentries where category='food' and subcategory = 'others' group by contributor) c
on b.contributor = c.contributor
where category='food' and subcategory<>'others' and destid>0
group by b.contributor,blogaddress,cnt

When I execute the above query I get the below given output which is correct as per the data

Contributor Baseaddress Recipecnt others
Uma Balakumar 81 0
Uma Shogalingam 136 1
umaudayshanker 1 0
umpc 2 1
uropinion 0 0
ushasuryamani 19 2

I want an sql query which will display the top bloggers, sorting the output data in the descending order. The result should be displayed as:

Uma Shogalingam 136 1
Uma Balakumar 81 0
ushasuryamani 19 2
umpc 2 1
umaudayshanker 1 0
uropinion 0 0
Oct 7 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 2,878
use the ordinal position of the field

ORDER BY 4 DESC will sort the result set using the fourth column in descending order.

-- CK
Oct 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.