Gaps and Islands
Gaps and islands is the SQL pattern for collapsing a sequence of rows into the contiguous runs (islands) and the breaks between them (gaps). The trick is a difference of two row numbers that stays constant inside a run, giving every row in the same island an identical group key you can then aggregate. It powers sessionization, login streaks, and contiguous date-range queries, and interviewers love it because the naive self-join answer is both slow and wrong on ties.
Every answer, concept and course, every paper breakdown, all published video lessons, hands-on FDE Lab missions, Premium PDF guides and companion files, the full practice-test bank and work-sample downloads. Referral Premium excludes guide PDFs and their companion files.
6 months · One payment · No auto-renewal
Study alongside free video lessons.
Related course lessons
- Resolve identities without hiding uncertain or unmatched records →
30 min · Free with sign-in
Foundations of Forward Deployed Engineering · syllabus - Declare the grain and prove that the totals survive joins →
30 min · Free with sign-in
Foundations of Forward Deployed Engineering · syllabus - Make replay, quarantine and reconciliation part of the pipeline contract →
30 min · Free with sign-in
The FDE Engagement · syllabus
