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

What is the difference between an application and a program?

578


Name some changes done since version 3.0?

631


how to add list of items in a web application and win application?

1682


what are constructors and destructors?

1809


What is gui programming? : .NET Architecture

594






What are different types that a variable can be defined and their scopes ?

699


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

623


Can I create my own metadata attributes?

617


What is .net mobile input validation. : Microsoft dot net mobile

614


Explain about validation?

691


I can't be bothered with cas. Can I turn it off?

613


What is .net mobile utility controls. : Microsoft dot net mobile

590


what is tracing? Where it used?

697


Explain the number or character entered through keyboard gets converted to equivalent ascii code & it get stored on ram in the binary form.

612


How resource files are used in .net?

630