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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Max!!!!

Author  Topic 

bilencekic
Posting Yak Master

121 Posts

Posted - 2006-12-22 : 07:48:08
i have a table like this

ID-----Word-----Value

1-----Jack-----1
2-----Joe-----4
3-----Jack----7
4-----joe-----6
5-----Jack-----0


Well i need the word and the values which is the max on the same word.
Without ID column i can get this result
Jack-----7
Joe-----6

but i want the ID column too
so result will be like
3-----Jack-----7
4-----Joe-----6


so what is the query for this?

MS BLESS US

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-22 : 07:57:00
select t1.* from
(select word, max(value) mv from table group by word) x
inner join table t1 on t1.word = x.word and t1.value = x.mv


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bilencekic
Posting Yak Master

121 Posts

Posted - 2006-12-22 : 08:04:33
god will send you to the paratise =) i am sure.
thx it worked.

MS BLESS US
Go to Top of Page
   

- Advertisement -