how to find the 2nd higgest salary in the column for example
take table name is employee?
And also find bottom 2nd lowest salary ?

Answer Posted / vishnu

Here we can find out 2nd highest salary in many ways,
according to the situation we can select anyone…
1st Type:
select min(esal) from emp where esal in (select top 2 esal
from emp order by esal desc)

2nd Type:
select max(esal) from emp where esal not in(select max(esal)
from emp)

3rd Type:
select max(esal) from emp where esal <(select max(esal) from
emp )

4th Type:
select Max(esal) from EMP a where 2=(select
COUNT(distinct(esal)) from EMP b where a.eSAL<=b.eSAL);

-----------------------------------------

For 2nd Lowest Salary:

-- 1st Type:
select min(esal) from emp where esal > (select min(esal)
from emp)

-- 2nd Type:
select * from emp where esal =
(
select max(esal) from emp where esal in (select top 2 esal
from emp order by esal)
)

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does .net remoting work?

622


Define cache coherency and how is it eliminated? : Dot net architecture

525


What is .net mobile forms? : Microsoft dot net mobile

516


Explain about clr?

587


Can I create my own metadata attributes?

535






Explain the difference between primary & secondary storage device? : .NET Architecture

535


What is private constructor? And it's use?

642


State the different levels of exceptional safety?

573


server.transfer limitation ?

1799


Explain the race around condition? : .NET Architecture How can it be overcome? : .NET Architecture

502


What is the purpose of Accordian in jquery? Where it can be used?

1862


Can you explain update progress control?

525


What is the importance of updatepanel control?

542


Explain dma? : .NET Architecture

546


how to use custom field validation

2057