Thursday, November 28, 2013

SQL Query for Find Highest Salary of a Employee.

Solution :

For  Highest Salary :

Select MAX(Salary) From EmployeeTable;

For 2Nd Highest Salary :

SELECT MAX(Salary) FROM EmployeeTable
WHERE Salary NOT IN (SELECT MAX(Salary) FROM EmployeeTable )

Find the nth highest salary using the TOP keyword in SQL Server :  

SELECT TOP 1 Salary
FROM (
      SELECT DISTINCT TOP N Salary
      FROM EmployeeTable
      ORDER BY Salary DESC
      ) AS Emp
ORDER BY Salary

No comments:

Post a Comment