Join waitlist
SQLCommunity question

RANK vs DENSE_RANK vs ROW_NUMBER

Asked by Sakshi Jain 28 days ago 3 answers 9 votes

always mix up the first two. small example anyone?

3 answers

Pooja Patel28 days agoMost voted8

salaries 100, 100, 90, 80

ROW_NUMBER: 1 2 3 4
RANK: 1 1 3 4 (skips after a tie)
DENSE_RANK: 1 1 2 3 (no gaps)

Manish Tiwari27 days ago3

and that's why nth highest salary should use DENSE_RANK

Mohit Saini27 days ago2

if your college lab has mysql 5.7 these won't work at all, need 8+. wasted an hour on that

Related questions

Go deeper

Want the full explanation, not just an answer?

Structured lessons on DSA, core CS, Java and interview skills, each ending in a quiz so you know it stuck.