Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 retrieve the Nth Maximum or Minimum Row in a table

Author  Topic 

lax
Starting Member

1 Post

Posted - 2004-05-26 : 10:19:46
Sir,
Can you please let me know the Query to retrieve the Nth Maximum or Minimum Row in a table
Say fore xample I want to retrieve the 5th Maximum or Minimum SALARY in the Employee TABLE.

Example : for N=2 it can be

SELECT MAX(SALARY)
FROM EMPLOYEE_SALARY
WHERE SALARY < (SELECT MAX(SALARY)
FROM EMPLOYEE_SALARY)

how about for N > 2.

X002548
Not Just a Number

15586 Posts

Posted - 2004-05-26 : 10:23:58
You could check out the homepage

http://www.sqlteam.com/item.asp?ItemID=16134



Brett

8-)
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-05-26 : 10:24:11
Hiya

Have a read of this : http://www.sqlteam.com/item.asp?ItemID=566

Does that answer your question ?



Damian
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-05-26 : 10:24:49


SNIPED



Damian
Go to Top of Page

gates_micro
Starting Member

29 Posts

Posted - 2004-06-02 : 02:23:29
declare @N int
set @N = 2
SELECT A.MARKS FROM ORDERTABLE A WHERE @N=
(SELECT COUNT(MARKS)+1 FROM ORDERTABLE B WHERE B.MARKS>A.MARKS) ORDER BY A.MARKS DESC
Go to Top of Page
   

- Advertisement -