SQLite 3 reference · Window Functions

SQLite LEAD() Function

Return a value from a following row in the window, such as the next order's date, or a default when there isn't one.

SQLite 3 Since 3.25.0

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

Syntax

lead(X, offset, default) OVER (PARTITION BY ... ORDER BY ...)

Parameters

ParameterDescription
X A column or expression.
offset optional How many rows ahead. Default: 1
default optional The value when there's no such row. Default: NULL

Return value

The value from that row.

Examples

The next row, with a defaultTry it yourself
SELECT order_id, order_date,
       lead(order_date, 1, 'none') OVER (ORDER BY order_date) AS next_order
FROM orders
ORDER BY order_date DESC
LIMIT 3;

Output

order_id | order_date | next_order
12 | 2026-06-15 | none
11 | 2026-05-30 | 2026-06-15
10 | 2026-05-09 | 2026-05-30
Who came nextTry it yourself
SELECT name, hire_date,
       lead(name) OVER (ORDER BY hire_date) AS hired_next
FROM employees
LIMIT 3;

Output

name | hire_date | hired_next
Sofia Reyes | 2018-03-01 | Omar Haddad
Omar Haddad | 2018-06-15 | Hannah Okafor
Hannah Okafor | 2019-02-04 | Mei Chen

Version history

VersionChange
SQLite 3.25.0Added

In other languages

Was this page helpful?