I use PHP and MySQL and I
have 2 tables:
- table score: have fields ‘user_id’ and ‘score’
- table user: have fields ‘user_id’ and ‘user_name’
People play game then store user_id and score in table ‘score’ every time game was ended. There are many rows for a single user in table score.
What I want?
I want to select top 10 players with distinct user_name to show on the list, so what is the correct sql? Code below is now my current sql, but it’s not show result what I want.
SELECT DISTINCT * FROM score as t1
INNER JOIN user AS t2 ON t1.user_id=t2.user_id
WHERE score>0
ORDER BY t1.score DESC
LIMIT 10
What is the mistake for this?
does this work? (not tested)