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
Syntax
lead(X, offset, default) OVER (PARTITION BY ... ORDER BY ...)
Parameters
| Parameter | Description |
|---|---|
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
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
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
| Version | Change |
|---|---|
| SQLite 3.25.0 | Added |
In other languages
LEAD()· PostgreSQL
Related
LAG()· Return a value from a previous row in the window, such as last month's total, or a default when there isn't one.LAST_VALUE()· Return a value from the last row of the window frame. Widen the frame to see the real last row of the partition.- SQL Window Functions · tutorial