tags:

views:

54

answers:

3

Hi,

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.

+5  A: 

Use:

SELECT t.*
FROM MTABLE t
ORDER BY t.score DESC
LIMIT 100
OMG Ponies
Thanks. Should really have thought of doing it that way!
Jason
@Mitch Wheat: My formatting! My beautiful formatting...
OMG Ponies
@OMG: well, i did wonder if it was intentional, but it didn't look like any of the standard forms!
Mitch Wheat
@Mitch Wheat: I appreciate your honesty. Not much, but a little =)
OMG Ponies
+2  A: 

Formatted:

Select * 
 from mtable 
order by score desc  
limit 100
Tahbaza
Thanks omg, didn't have the code format link on my mobile :)
Tahbaza
+1  A: 
SELECT columnList
FROM mTable
ORDER BY score DESC
LIMIT 100
Mitch Wheat
`columnlist`, eh? :)
OMG Ponies
@OMG : I feel dirty when I use '*'! ;)
Mitch Wheat