Thursday, 4 September 2014

SQL Command for finding Nth highest salary and name in the given Table

Select empname,salary from Employee a where N = (select count(distinct(salary)) from Employee b where a.salary<=b.salary);

* The above query is used to select the Nth highest salary with the name

SELECT MAX(Salary) FROM Employee
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee );

*The above query is used to select the Second highest salary


No comments:

Post a Comment