Find nth largest salary from employees table?

15 Views

Find nth largest salary from employees table?

By using following query we can find out the nth largest salary from employees table.

 SELECT salary FROM `employees` ORDER BY salary DESC LIMIT 1 OFFSET n-1

In the above query n is replaced by any number where n >= 1. Suppose you want to find fifth highest salary then you have to use offset = 5-1 i.e.: 4

The query will be:

 SELECT salary FROM `employees` ORDER BY salary DESC LIMIT 1 OFFSET 4

 

Tags:-
SQL
MySQL