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
  • 99
  • 1
  • 2
  • 4

3 Answers3

10

Use:

SELECT t.*
FROM MTABLE t
ORDER BY t.score DESC
LIMIT 100
Mitch Wheat
  • 288,400
  • 42
  • 452
  • 532
OMG Ponies
  • 314,254
  • 77
  • 507
  • 490
2

Formatted:

Select * 
 from mtable 
order by score desc  
limit 100
OMG Ponies
  • 314,254
  • 77
  • 507
  • 490
Tahbaza
  • 9,385
  • 2
  • 25
  • 39
1
SELECT columnList
FROM mTable
ORDER BY score DESC
LIMIT 100
Mitch Wheat
  • 288,400
  • 42
  • 452
  • 532