1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. How do ROW_NUMBER() and RANK() differ when two rows tie…

Added 30 Nov -0001

How do ROW_NUMBER() and RANK() differ when two rows tie for second place?

  1. Both assign identical numbers in every ordering
  2. RANK skips ties and numbers all rows sequentially
  3. ROW_NUMBER gives 2 and 3; RANK gives 2 and 2 Correct answer
  4. ROW_NUMBER gives 2 and 2; RANK gives 2 and 3

Correct answer

C. ROW_NUMBER gives 2 and 3; RANK gives 2 and 2

14 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs