Find nth largest salary from employees table?

Last updated 2 years, 4 months ago | 445 views 75     5

Tags:- SQL MySQL

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