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 are views in ms sql server?

594


How many types of the database links?

600


What is compound operators?

544


What methods do you follow to protect from sql injection attack?

514


What is pivot and unpivot?

638






What is scd (slowly changing dimension)? : sql server analysis services, ssas

590


Difference between DELETE and TRUNCATE?

613


What is the main purpose of having conversation group?

494


Write the syntax for stuff function in an sql server?

533


How to convert a unicode strings to non-unicode strings?

557


what method you can use to reduce the overhead of Reporting Services data sources?

149


Why do we use non clustered index?

551


What is the difference between index seek vs. Index scan?

574


What is difference between aggregate and analytic function?

478


What is clustered index

567