Skip to main content
InterviewHubPRO
Section Overview
Q14

Question 14 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

28%
SQL & Relational Databases (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is the difference between `ROW_NUMBER()`, `RANK()`, and `DENSE_RANK()`?

senior LevelMost AskedSystem Design

In Simple Words: When ranking rows with tied values (e.g. two employees with salary $100,000):

  • ROW_NUMBER(): Assigns strictly consecutive unique numbers regardless of ties ($1, 2, 3, 4$).
  • RANK(): Assigns the same rank to ties, and skips subsequent ranks to reflect the gap ($1, 2, 2, 4$).
  • DENSE_RANK(): Assigns the same rank to ties, but never skips ranks ($1, 2, 2, 3$).