Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. ROW_NUMBER vs RANK vs DENSE_RANK

SQL · Window Functions

ROW_NUMBER vs RANK vs DENSE_RANK

Mediumsql-18
row_numberrankdense_rank

Question

What is the difference between ROW_NUMBER, RANK, and DENSE_RANK?

Solution

Suppose salaries are:

100
100
90
80

Results:

ROW_NUMBER:   1  2  3  4
RANK:         1  1  3  4
DENSE_RANK:   1  1  2  3

ROW_NUMBER

Every row gets a unique number.

RANK

Ties receive the same rank, and gaps are created.

DENSE_RANK

Ties receive the same rank, but no gaps.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext