MainMenu

Home Java Overview Maven Tutorials

Sunday 15 January 2017

SQL Query to find second highest salary

Query to get second highest salary from table.


Consider the below Table : Salary
Emp_idEmp_Salary
0125000
0230000
0335000

Query 1 :Using a function Select MAX(Emp_salary) from Salary Where Emp_salary < (Select MAX(Emp_salary) from Salary)
Result :

Emp_Salary
30000


Query 2 :Using Limit Select Emp_salary from Salary order by Emp_salary desc Limit 1,1 Result :

Emp_Salary
30000


Note : Limit a,b means left a rows from top and show b number of rows.

Query to get 3rd highest salary from Employee table.

Consider the below Table : Salary:
Emp_idEmp_Salary
0125000
0230000
0335000

Query 1 :Using a function Select MAX(Emp_salary) from Salary Where Emp_salary < (Select MAX(Emp_salary) from Salary Where Emp_salary < (Select MAX(Emp_salary) from Salary) ) Result :

Emp_Salary
25000


Query 2 :Using Limit Select Emp_salary from Salary order by Emp_salary desc Limit 2,1 Result :

Emp_Salary
25000


Tag : Query to get second highest salary without function,Query to get 3rd highest salary from employee table

No comments:

Post a Comment