Write a query to get 2nd maximum salary in an employee table ?

Answer Posted / mark berlin.

REM solution #1:
select * from(
select distinct nvl(salary,-1) as sal
from employees
where nvl(salary,-1) < (select max(nvl(salary,-1)) from
employees)
order by nvl(salary,-1) desc)
where rownum=1;
REM Solution #2
select * from (
select distinct salary from employees
order by salary
desc
)
where rownum < 3
minus
select * from (
select distinct salary from employees
order by salary
desc
)
where rownum =1;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What version is sql?

565


Explain what is dbms?

589


How do I start pl sql?

500


Can a foreign key be null?

599


Can we perform dml on view?

561






What are user defined functions?

588


How many unique keys can a table have?

571


Explain how can you save or place your msg in a table?

601


How to return an array from java to pl/sql?

603


What is the limitation on the block size of pl/sql?

536


Can function return multiple values in sql?

537


What does (*) mean in sql?

535


What is a function in oracle pl sql?

551


Why is normalization important?

549


How does a self join work?

528