can anyone tell me that what is the main difference between RANK() and DENSE-RANK() ...
thanks in advance
home / developersection / forums / difference between rank() and dense_rank() in sql server.
can anyone tell me that what is the main difference between RANK() and DENSE-RANK() ...
thanks in advance
Sunil Singh
23-Nov-2017RANK Function skips rankings if there is a tie where as DENSE_RANK willnot
For example
If you have 2 rows at rank 1 and you have 5 rows in total
Rank() returns-1, 1, 3, 4, 5
DENSE_RANK RETURN - 1, 1, 2, 3 ,4
lets take an example to understand
Using rank()
select Name,salary,
rank() over (Order by Salary desc) as [rank] from salary
Using dense_rank()
select Name,salary,
dense_rank() over (Order by Salary desc) as [rank] from salary
output