Skip to main content
Module 13 · Lesson 3 of 451/57 in the course~16 min
Module lessons (3/4)

Rankings: ROW_NUMBER, RANK, and DENSE_RANK

Lesson preview5 hands-on exercises readySQL Course · Module 13 — Window Functions

Assign row numbers and leaderboard ranks with predictable tie-breaking.

What you'll learn in this lesson

  • Master the use of ORDER BY in OVER (...) to produce determined rankings.
  • Clearly distinguish ROW_NUMBER, RANK and DENSE_RANK in the management of ties and numerical gaps.
  • Apply the Top-N / group deduplication pattern by combining ROW_NUMBER() into a CTE and WHERE rn = 1.

Overview

The ranking functions assign an ordered number to each row of the window and necessarily require ORDER BY within OVER (...). Understanding which of the three sisters to choose (ROW_NUMBER, RANK, DENSE_RANK) makes the difference between correct pagination and an unbalanced ranking on equal merit.

Toggle between ROW_NUMBER, RANK and DENSE_RANK in the simulator: watch the fourth column of Engineering (55.000, 55.000, 42.000) to see the 1, 1, 3 (RANK) values transform into 1, 1, 2 (DENSE_RANK) live!

Sections covered in this lesson

  1. 11. Mental Model: How They Reason About Equal Merit (55k, 55k, 40k)
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: Ex-Aequo Effect on DENSE_RANK vs RANK
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 13 — Window Functions

Unlock "Rankings: ROW_NUMBER, RANK, and DENSE_RANK" and the full SQL Course curriculum

Assign row numbers and leaderboard ranks with predictable tie-breaking.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in SQL Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.