How to retrieve a second highest salary from a table?
Note:Suppose salaries are in duplicate values
eg:
Name Sal
Malli 60000
Pandi 60000
Rudra 45000
Ravi 45000

Answer Posted / shriram

You can also do it by the following query ..

select * from (select name,salary,rank() over(order by
salary desc as r) from employee) where r = 2;

The above query returns the 2nd highest salary from the table.

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is sql a scripting language?

521


Explain the update statement in sql

562


Can ddl statements be used in pl/sql?

597


Which command is used to delete a package?

577


What is sql query optimization?

547






Are left and right joins the same?

534


What does where 1 1 mean in sql?

550


What is the use of desc in sql?

496


What is the difference between view and stored procedure?

498


How do you update a sql procedure?

527


How delete all records from table in sql?

555


What is pragma in pl sql?

602


What is the difference between alter trigger and drop trigger statements?

602


what are the types of join and explain each? : Sql dba

534


What is the difference between a procedure and a function?

494