TO FIND THE SECOND HIGHEST SAL

by Vijayaprasad 2010-02-15 16:31:53

TO FIND THE SECOND HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select max(sal) from emp)

TO FIND THE 3RD HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select distinct top 2 sal from emp order by sal desc)

TO FIND THE Nth HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select distinct top N-1 sal from emp order by sal desc)

Tagged in:

1138
like
0
dislike
0
mail
flag

You must LOGIN to add comments