Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
An operations screen lists deliveries newest first, five to a page. Support have reported that a delivery sometimes shows up on both page 1 and page 2, and that another one they were looking for never appears at all. Return page 2 — rows six through ten of the newest-first list — with an ordering that makes the paging stable across runs.
Result columns · in this order
delivery_id | Delivery identifier. |
city | City the delivery was made in. |
delivered_on | Date the delivery completed. |
minutes | Delivery time in minutes. |
How to approach it
Order by the date descending, then by a unique column, and only then apply LIMIT and OFFSET.
Sample input
| delivery_id | city | courier | minutes | delivered_on |
|---|---|---|---|---|
| 1 | Bengaluru | Asha | 18 | 2026-03-01 |
| 2 | Bengaluru | Asha | 22 | 2026-03-01 |
| 3 | Bengaluru | Rohit | 26 | 2026-03-02 |
| 4 | Bengaluru | Asha | 28 | 2026-03-02 |
| 5 | Bengaluru | Rohit | 30 | 2026-03-03 |
| 6 | Bengaluru | Meera | 30 | 2026-03-03 |
| 7 | Bengaluru | Meera | 34 | 2026-03-04 |
| 8 | Bengaluru | Rohit | 41 | 2026-03-04 |
| 9 | Bengaluru | Asha | 150 | 2026-03-05 |
| 10 | Pune | Kabir | 20 | 2026-03-01 |
| 11 | Pune | Kabir | 24 | 2026-03-01 |
| 12 | Pune | Nita | 26 | 2026-03-02 |
| 13 | Pune | Nita | 30 | 2026-03-02 |
| 14 | Pune | Kabir | 33 | 2026-03-03 |
| 15 | Pune | Nita | 36 | 2026-03-03 |
| 16 | Pune | Kabir | 45 | 2026-03-04 |
| 17 | Pune | Nita | 62 | 2026-03-05 |
| 18 | Pune | Kabir | 240 | 2026-03-05 |
| 19 | Chennai | Vikram | 19 | 2026-03-01 |
| 20 | Chennai | Priya | 23 | 2026-03-01 |
| 21 | Chennai | Vikram | 27 | 2026-03-02 |
| 22 | Chennai | Priya | 30 | 2026-03-03 |
| 23 | Chennai | Vikram | 38 | 2026-03-03 |
| 24 | Chennai | Priya | 52 | 2026-03-04 |
| 25 | Chennai | Vikram | 71 | 2026-03-04 |
| 26 | Chennai | Priya | 96 | 2026-03-05 |
26 rows — scroll inside the table to see them all.
Expected output
| delivery_id | city | delivered_on | minutes |
|---|---|---|---|
| 24 | Chennai | 2026-03-04 | 52 |
| 16 | Pune | 2026-03-04 | 45 |
| 8 | Bengaluru | 2026-03-04 | 41 |
| 7 | Bengaluru | 2026-03-04 | 34 |
| 23 | Chennai | 2026-03-03 | 38 |
5 rows — all rows shown.
Constraints
delivered_on descending.delivery_id descending, which keeps newer ids above older ones within a day and is unique by definition.delivery_id, city, delivered_on and minutes.Worked example
Twenty-six deliveries share only five dates, so ORDER BY delivered_on DESC leaves large groups of rows tied. Four deliveries — 25, 24, 16, 8, 7 — all completed on 2026-03-04, and nothing in that ORDER BY says which comes first.
Page 1 takes five of them in whatever order the engine produced. Page 2 skips five and takes the next five — but if the engine ordered the tied rows differently on the second query, the two pages are cut from two different lists. A row can appear twice, and a row can vanish.
Adding delivery_id DESC makes the sort total, so page 1 ends at delivery 25 and page 2 begins at delivery 24 every single time.
What this tests
Whether you know that LIMIT and OFFSET are meaningless without a deterministic sort — the single most common pagination bug in production.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.