Here we are going to find the
second highest salary in the Table
Employess:
|
SQL Statement:
SELECT MIN(Salary)
FROM Employees
WHERE EmpID IN
(
SELECT TOP 2 EmpID
FROM Employees
ORDER BY Salary Desc
)
The same query can be re-written
using a derived table, as shown below, and it performs twice
as fast as the above query:
as fast as the above query:
SELECT MIN(Salary)
FROM
(
SELECT TOP 2 Salary
FROM Employees
ORDER BY Salary DESC
) AS A
FROM
(
SELECT TOP 2 Salary
FROM Employees
ORDER BY Salary DESC
) AS A
Result LookLike This:
EmpId
|
EmpName
|
Salary
|
5
|
Mathan
|
7890
|
No comments:
Post a Comment