LEAD looks at the next row
LEAD returns a value from the following row, so the current row can be compared with what comes next. ORDER BY inside OVER decides what next means. The final row has no following row, so its LEAD value is NULL.
A tiny example
In plain English: Show me each term's score next to the score from the term that follows.
SELECT term, LEAD(score) OVER (ORDER BY term) AS next_score
FROM results;What comes back
| term | next_score |
|---|---|
| Autumn | 80 |
| Spring | 90 |
| Winter | NULL |
Each row peeks at the next term's score — Winter is last, so there's nothing ahead.
Related SQL lessons
Ready for a break?
Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.
play today's sip