Common Scoretable SQL questions: How can I group scores by name?
For example, you've a hi-score table where the top 14 scores are all in the name of A.L.F and you want to show only A.L.F 's best score to give others a chance at position 2, 3 etc - prevent A.L.F from dominating the top slots.
The original SQL you might have is
$SQLAST="Select * from database_tablename order by score desc LIMIT 100";
And if you change it to this:
$SQLAST="Select *, MAX(score) as max_score from database_tablename GROUP BY name ORDER BY max_score desc LIMIT 0,100";
Then you'll have the result of only one identical name entry per set of results.
|