1.how to find nth highest salary| max salary
different ways
How to find max salary
different ways
How to find max salary
Syntax:- select max(col_name) from table_name
Example:- select max(salary) from employee
How to find 2nd highest salary
Example:- select max(salary) from employee
where salary<(select max(salary) from employee)
How to find top 2 highest salary
Example:- select distinct top 2 salary
from employee
order by salary desc
How to find nth highest salary using sub query
Example:- select top 1 salary from
(select distinct top 1 salary
from employee
order by salary desc)
result
order by salary
Here we used the sub query to find the nth highest salary but above query gives the top first salary but you needs 2nd,3nd,4nd,5nd...............salary we need to modify the query like this.you need 3nd highest salary then put distinct top 3.....
Example:-select top 1 salary from
(select distinct top 1..(2nd,3nd,4nd,5nd....nth) salary
from employee
order by salary desc)
result
order by salary