Saturday 26 July 2014

How to find second highest or maximum salary of Employee in Sql Server

find second highest salary of employee

Description:-

in this example we explain that how to find second highest salary of the employee in sql server table. This is the most important question that is asked by interviewer in any interview that is write query for find second second highest salary of employee in sql table or fetch record that have second highest salary.

We all listen that How to find second highest or second maximum salary of an Employee is one of the most frequently asked question in interview.

Restrict the size of File when Uploaded How to Restrict the size of File when uploaded by user

Dynamically Read/Write File in asp.Net How to Read Write File in Asp.Net using C#


There are many ways to find second highest salary of an employee are as below:
--Second maximum salary using sub query and IN clause

SELECT max(salary) FROM Employee WHERE salary NOT IN (SELECT max(salary) FROM Employee);

--Second maximum salary using sub query and LIMIT keyword

SELECT salary  FROM (SELECT salary FROM Employee ORDER BY salary DESC LIMIT 2) AS emp ORDER BY salary LIMIT 1;


--Second maximum salary using sub query and TOP keyword

SELECT TOP 1 salary FROM ( SELECT TOP 2 salary FROM employees ORDER BY salary DESC) AS emp ORDER BY salary ASC

--Second maximum salary using sub query and < operator

SELECT max(salary) FROM Employee WHERE salary < (SELECT max(salary) FROM Employee);



0 comments:

Post a Comment