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 / bibu

This IS HELP FULL 1ST ,2ND,3RD,4TH ANY HIGHEST SALARY U WRITE THIS QUERY.

SELECT * FROM Table_Name ALIAS_NAME 1
WHERE &N=(
SELECT COUNT(DISTINCT(WHICH COL U WANT THAT COL_NAME))
FROM Table_Name ALIAS_NAME 2
WHERE ALIAS1.CoL<=ALIAS2.Col
)

EX:
SELECT * FROM Emp E1
WHERE &N=(SELECT COUNT(DISTINCT(Sal))
FROM Emp E2
WHERE E1.Sal<=E2.Sal)

Is This Answer Correct ?    11 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a heap in sql?

519


what are myisam tables? : Sql dba

541


how to select unique records from a table? : Sql dba

622


What are the query optimization techniques?

528


What is a dynamic query?

563






How do you delete data from a table?

533


What are the advantages of sql? Explain

641


Explain what is sql*plus?

662


What are the steps for performance tuning.

833


What is field delimiter?

627


What is row_number () in sql?

533


What is pragma in sql?

610


what are null values? : Sql dba

537


What is cursor and its types?

548


what are wild cards used in database for pattern matching ? : Sql dba

539