Home > other >  How to select multiple rows at specfic index in MYSQL Database and order them?
How to select multiple rows at specfic index in MYSQL Database and order them?

Time:10-26

If I have a table that consists of ids and scores, something like this:

ID Score
a 10245
b 15
c 1256
d 1563

and so on for hundreds of scores, how can I pick the top 50-100 scores in the table?

I know I can order the scores using

SELECT * FROM table ORDER BY score

I also know MYSQL has USE INDEX but I cant seem to make it work. All help is appreciated.

CodePudding user response:

You want to order the score from highest score to lowest score in descending order (because by default it will be from lowest to highest score)

ID Score

a 10245

d 1563

c 1256

b 15 ..... so on

you will do that

SELECT * FROM table ORDER BY score DESC LIMIT 50;
SELECT * FROM table ORDER BY score DESC LIMIT 100;

* DESC to sort from highest score to lowest

* LIMIT 50 to pick the first 50 results

* LIMIT 100 to pick the first 100 results

  • Related