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 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you declare a user-defined exception?

718


How do you create an update query?

702


how to escape special characters in sql statements? : Sql dba

716


How do I save a sql query?

735


What are the different schemas objects that can be created using pl/sql?

729






How do you rename a table in sql?

736


What has stored procedures in sql and how we can use it?

765


how can we submit a form without a submit button? : Sql dba

725


Why procedure is used in sql?

754


what is bcp? When is it used?

772


How many row comparison operators are used while working with a subquery?

754


What are the different datatypes available in PL/SQL?

754


How do you remove duplicate records from a table?

676


What is AUTH_ID and AUTH_USER in pl/sql ?

1939


what is self-join? : Sql dba

756