HomeInterview QuestionsCan you explain rank, dense rank, and row number?

Can you explain rank, dense rank, and row number?

🟡 Medium Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

In SQL window functions, RANK() assigns a unique rank to each row within a partition, but leaves gaps when there are ties. For example, if two rows tie for first, both get rank 1, and the next distinct value gets rank 3. DENSE_RANK() also ranks rows within a partition but does not leave gaps; the next distinct value after a tie gets the next consecutive rank. ROW_NUMBER() simply numbers rows sequentially within a partition, regardless of duplicates, so ties are arbitrarily ordered. Use RANK() when you need to preserve gaps for reporting, DENSE_RANK() when you want continuous ranking, and ROW_NUMBER() when you need a deterministic unique identifier for each row.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500