what is syntex second or third highest salary.


thanks & Regards
Dhirendra sinha

Answer Posted / satish

select max(sal) from emp e1 where 1< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)

To make it generic if u want N'th highest salary;

select max(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)

And to get the N'th min sal :

select min(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal >= e2.sal)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What the class forname () does?

709


Explain activity monitors

799


You have to store user responses of ‘yes’ and ‘no’ what kind of data type is best suited for this task?

709


How to make a column nullable?

777


how many type of indexing in database?

732






What is a transaction and why is it important?

734


How are the unique and primary key constraints different?

788


What is the recovery model?

723


How to disable stored procedure sql server?

1220


Why use “nolock” in sql server?

722


What does REVERT do in SQL Server 2005?

711


How to generate create procedure script on an existing stored procedure?

694


Explain what is dbcc?

779


Explain what is “asynchronous” communication in sql server service broker?

666


Can we write trigger for view?

724