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.
| Author |
Topic |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-07-26 : 12:04:33
|
| tableID-----WordID-----Word-----Value-----Who1-----15-----play-----1100-----jack2-----15-----play-----1200-----joe3-----16-----work-----1000-----maria4-----16-----work-----1400-----black5-----17-----do-----1200-----brownID is identity and primarykeyi want to word that highst values paid by playersresult will be like this.ResultID-----ID-----WordID-----Word-----Value-----Who1-----1-----15-----play-----1200-----joe2-----4-----16-----work-----1400-----black3-----5-----17-----do-----1200-----browni tried max but i coulndt do it :D helpppMS BLESS US |
|
|
anand_d
Starting Member
9 Posts |
Posted - 2006-07-26 : 13:11:10
|
| select w1.* from worddata w1inner join(select word, max(value)as value from worddatagroup by word) w2on w1.word=w2.word and w1.value=w2.valueorder by id------- hope this works....a soln i can think of...Forum Experts: Any other thoughts. |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-26 : 13:17:36
|
Or...--datadeclare @t table (ID int, WordID int, Word varchar(10), Value int, Who varchar(10))insert @t select 1, 15, 'play', 1100, 'jack'union all select 2, 15, 'play', 1200, 'joe'union all select 3, 16, 'work', 1000, 'maria'union all select 4, 16, 'work', 1400, 'black'union all select 5, 17, 'do', 1200, 'brown'--calculationselect * from @t awhere Value = (select max(Value) from @t where WordID = a.WordID)order by id/*resultsID WordID Word Value Who ----------- ----------- ---------- ----------- ---------- 2 15 play 1200 joe4 16 work 1400 black5 17 do 1200 brown*/ Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-07-26 : 17:15:55
|
| yep but there are hunders of recordshow can i union allMS BLESS US |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-27 : 04:51:53
|
You don't. You only need the calculation section. So you will have...select * from YourTable awhere Value = (select max(Value) from YourTable where WordID = a.WordID)order by id Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-27 : 09:11:58
|
I have seen some questioners think that they need to use union all to prepare data without knowing that union all is given an example MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|