Abhijeet Kumar|Software Engineer|Bangalore|
Office : 8041068296
Mobile : +91-9342038171
Email : abhijeet....@gmail.com
A R I C E N T
I thought it's correct answer for you question .
For particular example of employee :
How to get 1st, 2nd, 3rd, 4th, nth topmost salary from an Employee table
The following solution is for getting 6th highest salary from Employee table ,
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
You can change and use it for getting nth highest salary from Employee
table as follows
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
Regards
Vijayakumar .
On 8 June 2011 15:35, Abhimanyu Singh <abhiv...@gmail.com> wrote:
>
> Hi,
> Below query also fetch desired result :-
>
> select distinct(SAL) from (select SAL,dense_rank() over (order by SAL desc) ranking from test ) where ranking=n;
>
> i executed query posted by nishant and getting different result if two or more salary are equals.
>
> Table Name :- test
> ID SAL
> 1 100
> 2 200
> 3 500
> 4 300
> 5 600
> 6 700
> 7 500
> 8 600
>
>
> I executed below query :-
> select * from test r1 where 2 = (select count(*) from test where SAL >= r1.SAL); // No result found