Calculate and Return Page Two
Return page two of page_events with page size four, ordered by event_time descending and event_id descending.
- Sorting
- Top-N
Exercise brief
Understand the request
Operations dashboard engineer An event feed displays four rows per page using newest-first offset pagination.
Skip the first 5 employees by employee_id and return the next 5. Show first_name, last_name, salary, employee_id.
Return
- Return rows five through eight of the ordered feed.
- Return event_id, event_time, stream, and severity.
Constraints
- Calculate OFFSET as (page - 1) × page_size.
- Use event_id to resolve equal timestamps.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
page_events
event_idINTEGERevent_timeTIMESTAMPstreamTEXTseverityINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Page two starts after one complete page.
Hint 2
For page 2 and page size 4, the offset is 4.
Hint 3
Order by event_time DESC, event_id DESC before applying OFFSET and the row limit.
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 ORDER BY event_time DESC, event_id DESC LIMIT 4 OFFSET 4;Why this works
Offset pagination uses OFFSET = (page - 1) × page_size. The unique secondary key is essential because several event timestamps tie across page boundaries.
Success check
The query returns exactly the second deterministic four-row page.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| event_id | event_time | stream | severity |
|---|---|---|---|
| 104 | 2025-05-04 08:00:00 | orders | 5 |
| 107 | 2025-05-03 09:00:00 | payments | 4 |
| 106 | 2025-05-03 09:00:00 | orders | 4 |
| 108 | 2025-05-03 08:00:00 | orders | 4 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Ranking & NTH Value
Solve deterministic ranking, top-N, distribution, positional-frame, and rolling-window problems.
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
Open the interactive workspace and practice across SQL topics.