How to find the second largest salary in the emp database and
also How to find 3rd,4th and so on ........ in the emp database

plz mail the answer @ mak2786@gmail.com

Answer Posted / s n yagneswara babu

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)

yagneswara babu
yagnesh_sn@yahoo.co.in

Is This Answer Correct ?    39 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if you add a new index to large table?

504


What is dbcc updateusage?

528


What is a mutating table error and how can you get around it?

529


How to return the top 5 rows from a select query in ms sql server?

579


How will you go about resolving deadlocks?

534






What is the advantage of sql server?

531


How would we use distinct statement? What is its use?

596


What is an index in sql?

541


How do you identify a foreign key?

590


Explain why variables called the most powerful component of ssis?

521


What is an indexing technique?

484


How to change the ownership of a schema in ms sql server?

546


What are trace flags?

583


List down some advantages of sql stored procedure?

546


What are the steps you should follow to start sql server in single-user mode?

474