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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Max Query( Based on two table)

Author  Topic 

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-19 : 08:04:48
i've two table Rate and Topic

Sample Table

Table name==>Topic
---------------------
Topic|TID|
-----|---|
hddgg|1
trgsd|2
vnvnv|3
sdfsd|4
dfsdf|5
dsdff|6
........
........
-----------------
above table TID is primary key

next table

Table Name==>Rate
-------------------
RID|TID|Rate
---|---|--------
1--|2--|4
2--|5--|3
3--|2--|3
4--|2--|2
5--|1--|1
6--|2--|1
7--|2--|2
8--|5--|3
9--|1--|4
.........
........

above table RID is primary key and TID is foreign key..

i need Top 3 Topic but based on Maximum Rate of value

any query.........


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-19 : 08:11:15
[code]
select top 3 t.Topic
from Topic t inner join Rate r
on t.TId = r.TID
group by t.Topic
order by sum(r.Rate) desc
[/code]


KH

Go to Top of Page

Easwar
Yak Posting Veteran

59 Posts

Posted - 2007-03-19 : 08:33:10
Thank you sir..............

now that query worked......
Go to Top of Page
   

- Advertisement -