Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select row based on max value of a field

Status
Not open for further replies.

hvass

Programmer
Mar 16, 2002
192
GB
I am trying to select a particluar row with the maximum score from a group of records - sounds simple maybe it is but it has got me so any suggestions would be very much appreciated

from myfile
------
fkey,urn,score
1,1002,80
1,1003,100
2,2004,100
2,2005,80
3,3006,100
4,4007,80

I want to get

1,1003,100
2,2004,100
3,3006,100
4,4007,80

select
fkey,
urn,
max(score)
from myfile group by fkey;

gives me max score of 100 but with an arbitrary urn

select
a.fkey,
a.urn,
a.score as ascore,
max(b.score) as bscore
from myfile a inner join myfile b using(fkey)
group by fkey
having ascore=bscore;

seems to give me a different problem it only picks cases where the first record in the set happens to be the one with the max score

Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top