How to find the lowest 3 values in a results set?
Posted: Wed Aug 07, 2002 7:42 am
I have a MYSQL database like this:
I want to pull out all the data in the field POINTS where the NAME field is the same (SELECT points FROM results WHERE name = 'Matt' ) and then I want to find some way to work out the three lowest values in the results set and discard them and then add the remaining values together and enter them in another table.
The bit I'm having some trouble working out how to do is how to pull out the results and work out the lowest three values. I was wondering if I could use the min(arg1,arg2,arg3...) function to do this with a loop that repeats three times so that every time I go through the loop I would extract the lowest value but how do I get the data out of the database and into the arg1, arg2 etc values? Is there some sort of array command or something I could use?
Any help that anyone can offer would be great!
Code: Select all
NAME||POINTS
==========
Matt ||45
==========
Dave ||13
==========
Matt || 23
==========
Steve|| 14
==========
etcThe bit I'm having some trouble working out how to do is how to pull out the results and work out the lowest three values. I was wondering if I could use the min(arg1,arg2,arg3...) function to do this with a loop that repeats three times so that every time I go through the loop I would extract the lowest value but how do I get the data out of the database and into the arg1, arg2 etc values? Is there some sort of array command or something I could use?
Any help that anyone can offer would be great!