DIFFERENCE BETWEEN RANK() AND DENSE_RANK() IN SQL SERVER.

Manish Sahu

Total Post:47

Points:331
Posted by  Manish Sahu
 432  View(s)
Ratings:
Rate this:

can anyone tell me that what is the main difference between RANK() and DENSE-RANK() ...

thanks in advance

  1. Sunil Singh

    Post:45

    Points:323
    Re: Difference between RANK() and DENSE_RANK() in sql server.

    RANK 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


      Modified On Nov-24-2017 12:00:57 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!