# RANK vs DENSE_RANK: Difference and Comparison

The Standard Query Language helps a programmer in creating a program as per the needs and requirements. In this particular language, RANK and DENSE_RANK are two features that most people tend to use interchangeably, but the truth is that these two are completely different from one another when we look from the depth.

## Key Takeaways

1. Rank assigns a unique number to each item based on its order, while dense rank assigns a unique number to each item based on its order but does not leave gaps.
2. Rank does not skip any number while assigning the rank, while dense rank can skip numbers if there are ties.
3. Rank is commonly used in standard SQL, while dense rank is used in analytical functions.

## RANK vs DENSE_RANK

The RANK function assigns a unique rank to each row in the result set based on a specific ordering criterion. If two or more rows have the same value for the ordering criterion, they will be assigned the same rank, and the next rank will be skipped. The DENSE_RANK function assigns a unique rank to each row in the result set, even if two or more rows have the same value for the ordering criterion.

RANK in the Standard Query Language can be understood as a feature that allows the programmer to categorize and evaluate a certain set of numbers.

This feature provides a particular ranking to all the numbers, and when the same number is repeated, the rank is also repeated with respect to those two numbers. But a very unique characteristic of this feature is that when it allows a similar rank to two or more numbers, it always skips the next number.

While on the contrary, DENSE_RANK happens to be slightly different from the previous one. DENSE_RANK in the Standard Query Language can be understood as a feature that allows the programmer to categorize certain data without skipping any number, even after allowing similar ranks.

This characteristic exists as the major distinguishable feature of this element.

## What is RANK?

In the computer programming language named standard query language or SQL, rank is a very basic feature that many programmers use to categorize a different set of data. This function allows the user to simplify the provided data and comprehend the information in a better manner.

A very unique feature of this function is that when two or more numbers are repeated because of their quantity, a similar rank is provided to them, as explained before. But when this is done, the ranking order skips the next number that follows that particular rank number.

Let us take an example to understand this. In the span of five years, the company has produced different quantities of rice that are 100KG, 200KG. 300KG, 300KG, 400KG. In this data, the ranking will be 1, 2, 3, 3, and 5.

Also Read:  XFCE vs GNOME: Difference and Comparison

It can be seen in this example that the number 4 has been skipped in the order, and this happened cause of the repetition of the number 3.

## What is DENSE_RANK?

DENSE_RANK, as a feature present in the SQL language of programming, happens to be another unique but slightly different feature. While providing a rank, the highest to lowest quantities are categorized and ranked accordingly.

The quantities that happened to be different from one another are provided different rankings, while the quantities that happened to be similar to one another are provided similar rankings. But unlike rankings, in this particular function, no number is kept while ranking a distinguished set of data.

Let us take an example of this. In the span of five years, a person has walked a particular distance each and every year. He walked 100 kilometres, 200 kilometres, 300 kilometres, 300 kilometres, and 500 kilometres, respectively.

The function of dense rank will provide a ranking of 1, 2, 3, 3, 4. The difference is visible as it did not skip the number 4. This feature is popular in programming because of its ability to categorize data present in a small column.

## Main Differences Between RANK and DENSE_RANK

1. Rank is a function provided in the SQL language that helps the programmer categorize a different set of data, but dense rank is another function that does a similar job but without skipping any number.
2. The purpose of ranking is to analyze the given rank of each and every room, while the purpose of dense ranking is to analyze the ranks of a particular column only.
3. Rank is written as RANK (), while dense rank is written as DENSE_RANK ().
4. In the ranking, the same rank is provided to similar numbers, but the next number following that particular rank is skipped. But in dense ranking, no number is scaped, and the rank follows a particular numerical order.
5. The ranking is easy to derive results from a bulk of data, while the dense ranking is suitable for deriving data from a particular set of columns or rows only.

## References

Last Updated : 07 August, 2023

One request?

I’ve put so much effort writing this blog post to provide value to you. It’ll be very helpful for me, if you consider sharing it on social media or with your friends/family. SHARING IS ♥️

What do you think?
10
7
10
7
2
5

### 10 thoughts on “RANK vs DENSE_RANK: Difference and Comparison”

1. This article provides a thorough and detailed explanation of the RANK and DENSE_RANK functions in SQL, which is very helpful for programmers working with this language.

2. The example provided to explain the function of RANK is very effective in illustrating how it works with repeated numbers and the skipping of ranks.

3. The article gives a clear and detailed explanation of the differences between RANK and DENSE_RANK in SQL, which is very helpful for programmers who are using this language.

4. The explanation of the meaning and process of RANK and DENSE_RANK is very clear and provides a comprehensive understanding of how they work in SQL.

5. The comparison between the number system of RANK and DENSE_RANK is very insightful and makes it clear how they handle similar numbers differently.

6. The explanation of the purpose of RANK and DENSE_RANK functions in SQL is very informative and helps in understanding their applications.

7. The example used to illustrate the skipping of ranks in the RANK function is very effective in demonstrating its behavior with repeated numbers.