Read one ordered page
Use OFFSET and FETCH to return a page after sorting the full result.
What you are trying to do
A request list shows two rows per page. The learner needs page two from four requests.
Work through it
- Read the unique QueueNumber sort key.
- Skip the first ordered row with OFFSET.
- Take the next two rows with FETCH.
Check your work
The result contains RequestId 20 and 30 with queue numbers 2 and 3. Request 40 is skipped and request 10 is on the next page.
Practice SQL
Open in SQL FlowSELECT RequestId, QueueNumber
FROM (VALUES (40, 1), (20, 2), (30, 3), (10, 4)) AS RequestQueue(RequestId, QueueNumber)
ORDER BY QueueNumber
OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY;
Knowledge check
Commands in this lesson
Next lesson Name a row's grain and key