MySQL Forums
Forum List  »  Newbie

Grouping only top 10 values
Posted by: Paul
Date: June 29, 2006 05:41PM


I am trying to figure out how to run something complex like this:

my table structure is similar to this:


each player has alot of rows with points.

The way we have our listings displayed is by doing a

SELECT player_id, SUM(player_points) as total GROUP BY player_id ORDER BY total DESC.

This works great but now we need to change our queries to reflect only top 10 scores of each player. So if a player has 50 entries for different points, we need to grab only the top 10 points and find the sum of that. Our table has over 20 million rows.

Can anyone guide me on how I would go on doing this? One way is by passing row by row into php and counting only top 10 rows. But this means going through all 20 million rows through php, very ineffective.

Any hints?

thank you

Options: ReplyQuote

Written By
Grouping only top 10 values
June 29, 2006 05:41PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.