1. [Home](<https://delaparra-services.nl/>) 
1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) 
1. [RANK / DENSE\_RANK](<https://delaparra-services.nl/knowledge-hub/rank-dense-rank>)

  

Category: SQL 

# RANK / DENSE\_RANK

  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    

## What is RANK / DENSE\_RANK?

 

RANK / DENSE\_RANK: Rank rows by an ORDER BY. RANK leaves gaps after ties (1,1,3); DENSE\_RANK does not (1,1,2). ` RANK() ` and ` DENSE_RANK() ` number rows by an ordering, such as highest score first. They differ in how they treat ties. With scores 90, 90 and 80, ` RANK ` gives 1, 1, 3, skipping a number after the tie; ` DENSE_RANK ` gives 1, 1, 2.

 

Definition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)

 

## Frequently asked questions about RANK / DENSE\_RANK

  

### How is RANK / DENSE\_RANK used in practice?

 

They are window functions, used with ` OVER (ORDER BY ...) `, and can be combined with ` PARTITION BY ` to rank within groups, such as the best-selling products per category.

    

### What should you keep in mind with RANK / DENSE\_RANK?

 

Choose based on what the ranking means. For a sports-style ranking, ` RANK ` matches what people expect. For "the top three price levels", ` DENSE_RANK ` is usually right. When you need exactly one row per position with no ties, use ` ROW_NUMBER() ` instead. All three are available in MySQL 8, PostgreSQL and SQLite.

    

### What does an example of RANK / DENSE\_RANK look like?

 

```
SELECT name, score, RANK() OVER (ORDER BY score DESC) AS r, DENSE_RANK() OVER (ORDER BY score DESC) AS dr FROM players;
```

 

## At a glance

   CategorySQL Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026

 

## More SQL terms

 

- [OVER](<https://delaparra-services.nl/knowledge-hub/over>) 
- [PARTITION BY](<https://delaparra-services.nl/knowledge-hub/partition-by>) 
- [phantom read](<https://delaparra-services.nl/knowledge-hub/phantom-read>) 
- [READ COMMITTED](<https://delaparra-services.nl/knowledge-hub/read-committed>) 
- [READ UNCOMMITTED](<https://delaparra-services.nl/knowledge-hub/read-uncommitted>) 
- [REPEATABLE READ](<https://delaparra-services.nl/knowledge-hub/repeatable-read>)

 

[All terms starting with R](<https://delaparra-services.nl/knowledge-hub#letter-r>)

 

## Skills

 

- ### SQL Performance Optimization Assistant

 

'Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Provides execution plan analysis, pagination optimization, batch operations, and performance monitoring guidance.'

 [View skill](<https://delaparra-services.nl/skills/sql-optimization>) [Download zip](<https://delaparra-services.nl/skills/sql-optimization/download>) 
- ### SQL Code Review

 

'Universal SQL code review assistant that performs comprehensive security, maintainability, and code quality analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Focuses on SQL injection prevention, access control, code standards, and anti-pattern detection. Complements SQL optimization prompt for complete development coverage.'

 [View skill](<https://delaparra-services.nl/skills/sql-code-review>) [Download zip](<https://delaparra-services.nl/skills/sql-code-review/download>) 
- ### Laravel Database Optimization

 

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

 [View skill](<https://delaparra-services.nl/skills/laravel-database-optimization>) [Download zip](<https://delaparra-services.nl/skills/laravel-database-optimization/download>)

 [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/rank-dense-rank/skills.zip>)

 

## Manuals

 

- [Writing SQL queries and migrations](<https://delaparra-services.nl/manuals/sql-queries-en-migraties>) 
- [PHP and Composer](<https://delaparra-services.nl/manuals/php-en-composer>)

 

## Related services

 

- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)

Perhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet. 
- [AI code review](<https://delaparra-services.nl/services#service-05>)

When you push your new change, I will review your code, help your agent avoid the same mistake again, and get your app ready for deployment.

 

## Need any help?

 

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.

  [Get in touch](<https://delaparra-services.nl/availability>)

[HTML version](https://delaparra-services.nl/knowledge-hub/rank-dense-rank)
