T616, “Null treatment option for LEAD and LAG functions”


BigQueryDb2 (LUW)DuckDBH2MariaDBMySQLOracle DBPostgreSQLSQL ServerSQLite200920112013201520172019202120232025⊘ 3.5.7 - 3.51.0✓ 2022 - 2025⊘ 2008R2 - 2019⊘ 8.3 - 18✓ 11gR2 - 23.26.1⊘ 11gR1⚠ 8.0.11 - 9.6.0b⊘ 5.0 - 5.7⊘ 5.1 - 12.1.2✓ 1.4.198 - 2.4.240⊘ 1.4.191 - 1.4.197⊘ 1.0.0 - 1.4.0a⊘ 9.7 - 12.1.3a⊘ 2.0
  1. Has alternative syntax
  2. Some variants
SELECT n
     , x
     , LEAD(x) IGNORE NULLS OVER(ORDER BY n)
     , LAG (x) IGNORE NULLS OVER(ORDER BY n)
  FROM (VALUES (0, 'A'), (1, null), (2, 'Z')) t(n,x)
nxLEAD(x) IGNORE NULS OVER(ORDER BY n)LAG(x) IGNORE NULS OVER(ORDER BY n)
0AZ
1ZA
2ZA

Variants and Alternatives

BigQuery 2026-01-03Db2 (LUW) 12.1.3DuckDB 1.4.0H2 2.4.240MariaDB 12.1.2MySQL 9.6.0Oracle DB 23.26.1PostgreSQL 18SQL Server 2025SQLite 3.51.0[lead|lag](…) respect nulls  [lead|lag](…)  ignore nulls  [lead|lag](…, 'ignore nulls')[lead|lag](…   ignore nulls )

Normative References

T616, “Null treatment option for LEAD and LAG functions” is defined as optional feature in ISO/IEC 9075-2:2023. It first appeared in SQL:2011.

You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-⁠sql.com on your radar.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on TwitterMarkus Winand on Bluesky
Copyright 2015-2026 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR