How do ROW_NUMBER() and RANK() differ when two rows tie for second place?
Correct answer
C. ROW_NUMBER gives 2 and 3; RANK gives 2 and 2
14 views
C. ROW_NUMBER gives 2 and 3; RANK gives 2 and 2
14 views
ROW_NUMBER always assigns distinct consecutive integers, breaking ties arbitrarily unless the ORDER BY inside the window is fully deterministic. RANK gives tied rows the same number and then skips ahead, so two rows sharing second place are followed by rank 4. DENSE_RANK is the third option, which shares the rank but does not skip, producing 2, 2, 3.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.