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
How do you go back in sql?
Why join is faster than subquery?
explain access control lists. : Sql dba
What are all the different types of indexes?
What is the difference between partitioning and sharding?
How do you update a sql procedure?
Why cross join is used?
When is a declare statement required?
what is the difference between truncate and delete statement? : Transact sql
List and explain the different types of join clauses supported in ansi-standard sql?
Can we use two order by clause in query?
What is the maximum number of columns in sql table?
What is a constraint?
How to use sql statements in pl/sql?
What is left join in postgresql?