Reputation: 121
I have a game where I'm saving each point to each player. Now I want to build a highscore where it lists the players with the best scores. but I want only the highest score per player visible.
Ex:
David 38 points
Elin 25 points
Kelly 3 points
And not:
David 38 points
David 35 points
Elin 25 points
Elin 23 points
Elin 20 points
etc etc
My code today:
$sql="select userID, poang from floppy ORDER BY poang DESC LIMIT 10";
$result=mysql_query($sql) or die(mysql_error()."<br />".$sql);
while($row = mysql_fetch_array($result)){
echo $row[userID]." ".$row['poang']." points<br />";
}
Anyone know how to do?
Upvotes: 0
Views: 67
Reputation: 13960
SELECT TOP 10 userID, MAX(poang) from floppy GROUP BY userID ORDER BY MAX(poang) DESC
Upvotes: 3