HomeInterview QuestionsBriefly explain row number, rank, and dense rank.

Briefly explain row number, rank, and dense rank.

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

💡 Model Answer

In SQL, window functions allow you to perform calculations across a set of rows related to the current row.

• ROW_NUMBER() assigns a unique sequential integer to each row within a partition, starting at 1. It does not consider any ties; every row gets a distinct number.

• RANK() assigns a rank to each row within a partition, but if two rows tie on the ordering expression, they receive the same rank. The next rank is incremented by the number of tied rows, leaving gaps. For example, if two rows tie for rank 1, the next row gets rank 3.

• DENSE_RANK() behaves like RANK() but does not leave gaps. Tied rows receive the same rank, and the next rank is simply the previous rank plus one.

These functions are useful for pagination, top‑N queries, and generating ordinal positions while handling duplicates appropriately.

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