Connecting Tech Pros Worldwide Help | Site Map

Sql query for sorting the output in the descending order

  #1  
Old October 7th, 2008, 07:38 AM
Newbie
 
Join Date: Sep 2008
Posts: 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 umabalakumar.sulekha.com 81 0
Uma Shogalingam umashogalingam.sulekha.com 136 1
umaudayshanker umaudayshanker.sulekha.com 1 0
umpc umpc.sulekha.com 2 1
uropinion uropinion.sulekha.com 0 0
ushasuryamani ushasuryamani.sulekha.com 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 umashogalingam.sulekha.com 136 1
Uma Balakumar umabalakumar.sulekha.com 81 0
ushasuryamani ushasuryamani.sulekha.com 19 2
umpc umpc.sulekha.com 2 1
umaudayshanker umaudayshanker.sulekha.com 1 0
uropinion uropinion.sulekha.com 0 0
  #2  
Old October 7th, 2008, 10:36 AM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,914
Provided Answers: 1

re: Sql query for sorting the output in the descending order


use the ordinal position of the field

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

-- CK
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting an Array - CSORT Nel answers 5 November 29th, 2005 12:35 PM
7.4, 'group by' default ordering? Mike Nolan answers 5 November 12th, 2005 01:33 AM
Calling All T-SQL Gods & Goddesses Martin answers 1 July 20th, 2005 04:50 AM