TGViewer
Data Analyst Interview Resources Data Analyst Interview Resources @dataanalystinterview ยท 52.5K subscribers
Post #1879 3.25K
๐Ÿง‘โ€๐Ÿ’ผ Interviewer: What's the difference between RANK() and DENSE_RANK() in SQL?

๐Ÿ‘จโ€๐Ÿ’ป Me: Here's a quick example using salaries:

SELECT name, department, salary,
RANK() OVER (ORDER BY salary DESC) AS rank_salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rank_salary
FROM employees;


โœ” Key Differences:
โ€“ RANK(): Skips ranks if there's a tie (e.g., two at #1, next is #3)โ€”great for competitions where gaps show true position.
โ€“ DENSE_RANK(): No gapsโ€”ranks increase sequentially (e.g., two at #1, next is #2)โ€”ideal for leaderboards or tiers without skips.

๐Ÿ“Œ Example:
If two people tie at 1st place:
โฆ RANK() โ†’ 1, 1, 3
โฆ DENSE_RANK() โ†’ 1, 1, 2

๐Ÿ’ก Use DENSE_RANK() when you want consistent rank steps, like in sales reportsโ€”add PARTITION BY department for per-group ranking!

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 4
More from @dataanalystinterview
  1. Oct 10, 2026๐Ÿ“ข Advertising in this channel You can place an ad via Telegaโ€คio. It takes just a few minuโ€ฆ
  2. Oct 9, 2026โœ…SQL Roadmap: Step-by-Step Guide to Master SQL ๐Ÿง ๐Ÿ’ป Whether you're aiming to be a backendโ€ฆ
  3. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
  4. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  5. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  6. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’