---
title: "How to find Nth highest salary?"  
description: "How to find Nth highest salary?"  
author: "Ravi Vishwakarma"  
published: 2026-03-17  
updated: 2026-04-14  
canonical: https://answers.mindstick.com/qa/116427/how-to-find-nth-highest-salary  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 2 minutes  

---

# How to find Nth highest salary?

## Answers

### Answer by Anubhav Sharma

Finding the **Nth [highest salary](https://www.mindstick.com/forum/34652/how-can-get-alternate-highest-salary-or-any-record-in-a-table-in-sql-server)** is a very [common](https://www.mindstick.com/articles/44657/10-common-reasons-why-printers-jam) [SQL](https://www.mindstick.com/articles/202/the-detailed-concept-of-stored-procedure-in-sql-server) [interview](https://www.mindstick.com/articles/329061/video-interviews-a-viable-tool-to-take-on-large-recruitments) question. There are [multiple](https://www.mindstick.com/forum/2323/handling-multiple-submit-button-in-asp-dot-net-mvc) ways to do it depending on your database.

## 1. Using `ORDER BY` + `LIMIT` (MySQL / PostgreSQL)

To find the **[Nth highest](https://www.mindstick.com/forum/33705/find-nth-highest-salary-in-sql-serever) salary**:

```plaintext
SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET N-1;
```

### Example (3rd highest salary):

```plaintext
SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 2;
```

## 2. Using Subquery (Generic SQL)

```plaintext
SELECT MAX(salary)
FROM employees
WHERE salary < (
    SELECT MAX(salary)
    FROM employees
    WHERE salary < (
        SELECT MAX(salary)
        FROM employees
    )
);
```

This works for fixed N (like 3rd), but not [scalable](https://yourviews.mindstick.com/view/88363/what-are-the-engineering-challenges-in-building-scalable-backends-for-live-dealer-casino-platforms) for [dynamic](https://www.mindstick.com/forum/1749/how-to-change-dynamically-layout-page-in-mvc4) N.

## 3. Using `DENSE_RANK()` (Best & Recommended)

```plaintext
SELECT salary
FROM (
    SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rank
    FROM employees
) t
WHERE rank = N;
```

### Example (2nd highest salary):

```plaintext
SELECT salary
FROM (
    SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rank
    FROM employees
) t
WHERE rank = 2;
```

## 4. Using `ROW_NUMBER()` (When duplicates matter)

```plaintext
SELECT salary
FROM (
    SELECT salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn
    FROM employees
) t
WHERE rn = N;
```

## Difference (Important for Interview)

- `DENSE_RANK()` → Handles duplicates (same salary gets same rank)
- `ROW_NUMBER()` → Always unique [ranking](https://www.mindstick.com/articles/339372/10-tips-to-boost-your-local-search-rankings)
- `RANK()` → Skips ranks when duplicates exist

## Pro Tip (Interview Answer)

If interviewer asks:

> “Best way?”

Answer:

Use `DENSE_RANK()` → clean, scalable, handles duplicates correctly


---

Original Source: https://answers.mindstick.com/qa/116427/how-to-find-nth-highest-salary

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
