| Author |
Topic |
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-25 : 01:57:10
|
| Hi All,i had tried this query but i was getting not the exact result select top 5 e.uncid ,e.uncname ,e.description ,e.starttime,e.endtime ,u.username ,r.ranking ,count(c.unccommentsid)as noofcomments from A e join B u on e.userid=u.userid join C r on e.uncid=r.uncid join D c on e.uncid=c.uncidwhere e.deleted=0 group by e.uncid,e.uncname,e.description,e.starttime,e.endtime,u.username,c.unccommentsid,r.ranking order by r.ranking descHere i was getting top 1 answer for all the top 5 answers |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-25 : 01:59:53
|
[code]select top 5 e.uncid , e.uncname , e.description , e.starttime , e.endtime , u.username , r.ranking , count(c.unccommentsid)as noofcommentsfrom A ejoin B u on e.userid=u.useridjoin C r on e.uncid=r.uncidjoin D c on e.uncid=c.uncidwhere e.deleted=0 group by e.uncid, e.uncname, e.description, e.starttime, e.endtime, u.username, c.unccommentsid, r.ranking order by r.ranking desc[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-25 : 02:05:16
|
OR this waySELECT TOP 5 e.uncid , e.uncname , e.description , e.starttime , e.endtime , u.username , r.ranking , c.noofcommentsFROM A e JOIN B u ON e.userid=u.userid JOIN C r ON e.uncid=r.uncid JOIN ( SELECT uncid, COUNT(c.unccommentsid) AS noofcomments FROM D GROUP BY uncid ) c ON e.uncid=c.uncidWHERE e.deleted = 0 ORDER BY r.ranking DESC KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-25 : 02:06:39
|
| K.Thank you .I got it |
 |
|
|
|
|
|