Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch one row per account id from list

I have a table with game scores, allowing multiple rows per account id: scores (id, score, accountid). I want a list of the top 10 scorer ids and their scores.

Can you provide an sql statement to select the top 10 scores, but only one score per account id?

Thanks!

like image 279
Kenzie Avatar asked Sep 18 '08 17:09

Kenzie


1 Answers

select username, max(score) from usertable group by username order by max(score) desc limit 10;
like image 149
zigdon Avatar answered Oct 17 '22 07:10

zigdon