Hi, thanks for all of the replies to my query. I'm not sure that I explained my problem very well as the solutions received are solutions to the problem I described, but not the one I meant :-) (I don't think anyway)
I have a table in the format: family | member | score -------------------------------- 1 | 1 | 10 1 | 2 | 15 1 | 3 | 12 1 | 4 | 17 2 | 1 | 5 2 | 2 | 7 2 | 3 | 9 2 | 4 | 10 3 | 1 | 4 3 | 2 | 8 3 | 3 | 2 I want the top 2 highest scorers for each family as in: family | member | score ------------------------------- 1 | 4 | 17 1 | 2 | 15 2 | 4 | 10 2 | 3 | 9 3 | 2 | 8 3 | 1 | 4 Thanks again, Rich mysql Jay Blanchard wrote: >[snip] >I want to retrieve members of each family that have the two highest >scoring values for a column. i.e the max and second max. >Is there a function similar to max() or greatest() that will return the >top 2 values when grouping by family ID? >[/snip] > >Try this query > >select foo, MAX(bar) >from table >order by bar DESC >limit 2; > >HTH! > >Jay > > > > > > >--------------------------------------------------------------------- >Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list archive) > >To request this thread, e-mail <[EMAIL PROTECTED]> >To unsubscribe, e-mail <[EMAIL PROTECTED]> >Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php