Today's question comes from Shibu T.:
Dear Mr. SQLGURU,
How do I get the second/third/fourth largest from a column of a single table?Shibu Thomas
Shibu,
In SQL 6.5:
|
In SQL 7.0:
|
(the 6.5 solution will also work under 7.0)
These queries will return the top X (in this case, 5) largest values of foo. If you're looking for a specific value, say the second largest, then you could use a cursor or a temp table to get to the correct value.
For more information on TOP
and ROWCOUNT
be sure to check out the following
articles here on 4Guys:
Sean
Read Other SQL Guru Questions |