LIMIT & OFFSET SQL Topic exerciseHardVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

Resume a Bounded Backfill Batch

Return the next three events after event_id 104, without reading beyond high-water event_id 110.

  • Filtering
  • Sorting
  • Top-N

Exercise brief

Understand the request

Data migration engineer A resumable backfill must stop at the high-water mark captured when the run began.

Resume a keyset-paginated backfill after event_id 104 while respecting the event_id 110 high-water mark.

Return

  • Return event_id, event_time, stream, and severity.
  • Return the next ascending three-row batch.

Constraints

  • Use exclusive lower and inclusive upper event_id bounds.
  • Order by event_id and apply a three-row limit.
  • Do not use OFFSET.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

page_events

  • event_idINTEGER
  • event_timeTIMESTAMP
  • streamTEXT
  • severityINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

The saved cursor is an exclusive lower bound.

Hint 2

The run high-water mark is an inclusive upper bound.

Hint 3

Filter 104 < event_id <= 110, order by event_id, then take three.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT event_id, event_time, stream, severity FROM page_events WHERE event_id > 104 AND event_id <= 110 ORDER BY event_id LIMIT 3;

Why this works

A high-water bound prevents a long-running backfill from chasing rows inserted after the run started. The lower cursor makes each batch resumable without rescanning skipped rows.

Success check

The batch resumes after 104 while remaining inside the frozen 110 boundary.

Expected result

Use this output to verify values, aliases, ordering, and row count.

event_idevent_timestreamseverity
1052025-05-04 08:00:00payments2
1062025-05-03 09:00:00orders4
1072025-05-03 09:00:00payments4

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.