Difference between Rank and Dense Rank

Published: 12 May 2023
on channel: Interview Preparation
2,738
107

#sql #sqlserver #techinterviews #interviewquestions

Difference between Rank and Dense_Rank in SQL Server:

Both RANK() and DENSE_RANK() are window functions used to assign a rank to each row within a result set, but there is a difference in how they handle ties:

RANK() assigns the same rank to the rows that have the same values and leaves gaps between the ranks of tied rows. For example, if two rows have the same value and rank 1, the next rank will be 3.

DENSE_RANK() assigns the same rank to the rows that have the same values, but does not leave gaps between the ranks of tied rows. For example, if two rows have the same value and rank 1, the next rank will be 2.


Watch video Difference between Rank and Dense Rank online without registration, duration hours minute second in high quality. This video was added by user Interview Preparation 12 May 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,738 once and liked it 107 people.