Concept Flow - OFFSET for pagination
Start Query
Apply ORDER BY
Skip OFFSET rows
Return LIMIT rows
Display Results
End
The query orders data, skips a number of rows using OFFSET, then returns a limited number of rows for pagination.
SELECT name FROM employees ORDER BY id LIMIT 3 OFFSET 2;
| Step | Action | Rows Considered | Rows Skipped (OFFSET) | Rows Returned (LIMIT) | Output Rows |
|---|---|---|---|---|---|
| 1 | Start query execution | All employees (5 rows) | 0 | 0 | None yet |
| 2 | Order rows by id | All employees ordered by id | 0 | 0 | id=1,2,3,4,5 |
| 3 | Skip OFFSET rows | Ordered rows | 2 | 0 | id=3,4,5 remain |
| 4 | Return LIMIT rows | Remaining rows after OFFSET | 2 | 3 | id=3,4,5 |
| 5 | Display results | Final output | 2 | 3 | Names of employees with id 3,4,5 |
| 6 | End | Query complete | 2 | 3 | 3 rows returned |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|
| Rows Considered | 5 unordered | 5 ordered by id | 3 after skipping 2 | 3 limited to 3 | 3 final rows |
| Output Rows | None | None | None | 3 rows selected | 3 rows displayed |
OFFSET skips a number of rows before returning results. LIMIT sets how many rows to return. Use ORDER BY to define row order. Common for pagination: OFFSET = (page-1)*page_size. Example: SELECT * FROM table ORDER BY id LIMIT 10 OFFSET 20;