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

Answer Posted / ahamed

The following solution is for getting 6th highest salary
from Employee table ,
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

or

SELECT MIN(Sal) FROM TableName
WHERE Sal IN
(SELECT TOP 6 Sal FROM TableName ORDER BY Sal DESC)


Reference:

http://blog.sqlauthority.com/2008/04/02/sql-server-find-nth-highest-salary-of-employee-query-to-retrieve-the-nth-maximum-value/

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

explain the difference between delete , truncate and drop commands? : Sql dba

553


How do you declare a constant?

532


What is trigger and stored procedure in sql?

560


Write an sql query to select all records from the table?

561


what is a view? : Sql dba

638






What can you do with pl sql?

569


What is the difference between inner join and left join?

550


What are the two different parts of the pl/sql packages?

570


Why is partition used in sql?

552


What is a clob in sql?

569


What is a loop in sql?

572


what is the difference between rownum pseudo column and row_number() function? : Sql dba

620


What is the difference between an inner join and an outer join?

516


how can we destroy the session, how can we unset the variable of a session? : Sql dba

554


Difference between table function and pipelined function?

589