lilzz
lilzz

Reputation: 5413

MySQL & PHP leaderboard query

I have a set of players and I want to select the top 5 scores from the tables and print out the username and scores in descending order, what's the SQL statement for that? and How to output the result?

Upvotes: 0

Views: 572

Answers (1)

maaudet
maaudet

Reputation: 2358

SELECT * FROM yourtable ORDER BY score DESC LIMIT 5

Explanations:

SELECT * FROM yourtable: we select yourtable.

ORDER BY score DESC: We order the results based on the column score and in descending order.

LIMIT 5: we limit the number of results by 5.

Upvotes: 1

Related Questions