Query to get second highest salary from table.
Consider the below Table : Salary
Emp_id | Emp_Salary |
---|---|
01 | 25000 |
02 | 30000 |
03 | 35000 |
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_id | Emp_Salary |
---|---|
01 | 25000 |
02 | 30000 |
03 | 35000 |
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 |
No comments:
Post a Comment