---
title: "Difference between RANK() vs DENSE_RANK()."  
description: "Difference between RANK() vs DENSE_RANK()."  
author: "ICSM Computer"  
published: 2026-05-04  
updated: 2026-05-04  
canonical: https://www.mindstick.com/interview/34502/difference-between-rank-vs-dense_rank  
category: "database"  
tags: ["database", "sql server"]  
reading_time: 2 minutes  

---

# Difference between RANK() vs DENSE_RANK().

The difference between `RANK()` and `DENSE_RANK()` is how they handle duplicate values when assigning ranks.

RANK():

- Assigns the same rank to equal values
- Skips the next rank(s) after a tie

Example:

```plaintext
SELECT name, score,
       RANK() OVER (ORDER BY score DESC) AS rank
FROM students;
```

Result:

```plaintext
Score | Rank
100 | 1
90 | 2
90 | 2
80 | 4
```

Here, rank 3 is skipped because two rows share rank 2.

DENSE_RANK():

- Assigns the same rank to equal values
- Does not skip ranks

Example:

```plaintext
SELECT name, score,
       DENSE_RANK() OVER (ORDER BY score DESC) AS dense_rank
FROM students;
```

Result:

```plaintext
Score | Dense Rank
100 | 1
90 | 2
90 | 2
80 | 3
```

Here, ranks continue without gaps.

Key difference:

- RANK(): gaps in ranking after duplicates
- DENSE_RANK(): no gaps in ranking

When to use:

- Use RANK() when ranking should reflect positions with gaps (like sports rankings: 1, 2, 2, 4)
- Use DENSE_RANK() when you want continuous ranking without gaps (1, 2, 2, 3)

## Answers

### Answer by ICSM Computer

The difference between `RANK()` and `DENSE_RANK()` is how they handle duplicate values when assigning ranks.

RANK():

- Assigns the same rank to equal values
- Skips the next rank(s) after a tie

Example:

```plaintext
SELECT name, score,
       RANK() OVER (ORDER BY score DESC) AS rank
FROM students;
```

Result:

```plaintext
Score | Rank
100 | 1
90 | 2
90 | 2
80 | 4
```

Here, rank 3 is skipped because two rows share rank 2.

DENSE_RANK():

- Assigns the same rank to equal values
- Does not skip ranks

Example:

```plaintext
SELECT name, score,
       DENSE_RANK() OVER (ORDER BY score DESC) AS dense_rank
FROM students;
```

Result:

```plaintext
Score | Dense Rank
100 | 1
90 | 2
90 | 2
80 | 3
```

Here, ranks continue without gaps.

Key difference:

- RANK(): gaps in ranking after duplicates
- DENSE_RANK(): no gaps in ranking

When to use:

- Use RANK() when ranking should reflect positions with gaps (like sports rankings: 1, 2, 2, 4)
- Use DENSE_RANK() when you want continuous ranking without gaps (1, 2, 2, 3)


---

Original Source: https://www.mindstick.com/interview/34502/difference-between-rank-vs-dense_rank

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
