Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select n largest values from a table

Tags:

sql

mysql

How can I select the 100 largest rows in a table based on a column 'score'?

I can find the largest score in the 'score' column with:

SELECT max(score) FROM mTable

And then obtain that row(s):

SELECT * FROM mTable WHERE score=largestScore

But how would I wrap this up and obtain the following 99 lower scored rows?

Thanks.

like image 881
Jason Avatar asked Sep 16 '25 11:09

Jason


1 Answers

Use:

SELECT t.*
FROM MTABLE t
ORDER BY t.score DESC
LIMIT 100
like image 60
OMG Ponies Avatar answered Sep 19 '25 01:09

OMG Ponies