SQLite 3 reference · Window Functions

SQLite DENSE_RANK() Function

Rank rows by the window's ORDER BY, giving ties the same rank without gaps after them (1, 2, 2, 3).

SQLite 3 Since 3.25.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

dense_rank() OVER (PARTITION BY ... ORDER BY ...)

Return value

An integer from 1.

Examples

rank() vs dense_rank()Try it yourself
SELECT name, title,
       rank() OVER (ORDER BY title) AS rank,
       dense_rank() OVER (ORDER BY title) AS dense
FROM employees
WHERE department = 'Engineering';

Output

name | title | rank | dense
Omar Haddad | CTO | 1 | 1
Priya Nair | Engineer | 2 | 2
Lucas Martin | Engineer | 2 | 2
Mei Chen | Engineering Manager | 4 | 3
Jonas Berg | Senior Engineer | 5 | 4
Top three salary levelsTry it yourself
SELECT DISTINCT salary, dense_rank() OVER (ORDER BY salary DESC) AS level
FROM employees
ORDER BY level
LIMIT 3;

Output

salary | level
250000 | 1
210000 | 2
165000 | 3

Version history

VersionChange
SQLite 3.25.0Added

In other languages

Was this page helpful?