# Write a SOQL query to find the Nth Highest Salary on an Employee__c object.

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Infosys, LTIMindtree, Tech Mahindra · **Tags:** soql, scenario, offset

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-find-the-nth-highest-salary-on-an-employee-c-object

## Answer

Use `ORDER BY ... DESC LIMIT 1 OFFSET N-1`. For the 3rd highest salary:

```soql
SELECT Id, Name, Salary__c FROM Employee__c
WHERE Salary__c != null
ORDER BY Salary__c DESC
LIMIT 1 OFFSET 2
```
In Apex, use a variable: `LIMIT 1 OFFSET :n` where `n = N - 1`. OFFSET max is 2,000. For distinct salaries, first group by `Salary__c` (aggregate) then apply the offset.

---
Source: ForceChallenges · last updated 2026-10-19
