2

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.

Jason
  • 119
  • 1
  • 2
  • 4

3 Answers3

10

Use:

SELECT t.*
FROM MTABLE t
ORDER BY t.score DESC
LIMIT 100
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
2

Formatted:

Select * 
 from mtable 
order by score desc  
limit 100
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Tahbaza
  • 9,486
  • 2
  • 26
  • 39
1
SELECT columnList
FROM mTable
ORDER BY score DESC
LIMIT 100
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541