DENSE_RANK assigns the same rank to tied values but does not leave gaps in the ranking sequence.
It is useful when ranking business results and you want consecutive ranking positions despite tied values.
Rank employees by salary within each department without ranking gaps.
SELECT
e.EmployeeName,
d.DepartmentName,
e.Salary,
DENSE_RANK() OVER (
PARTITION BY e.DepartmentID
ORDER BY e.Salary DESC
) AS SalaryRank
FROM Employees e
INNER JOIN Departments d
ON e.DepartmentID = d.DepartmentID;
Used in employee rankings, sales leaderboards, product rankings, and performance analysis.
- DENSE_RANK assigns rankings within groups.
- Tied rows receive the same rank.
- Ranking continues without gaps.
- PARTITION BY separates groups.
- Useful for business ranking scenarios.
What is DENSE_RANK?
DENSE_RANK assigns the same rank to tied values and continues with the next consecutive rank.
How does DENSE_RANK differ from RANK?
RANK can leave gaps after ties, while DENSE_RANK does not.