Example 1
Return the second page of two rows
This example skips the first two sorted rows and returns the next two.
Engine-specific syntax
Setup
CREATE TABLE posts (id INT, title VARCHAR(50));
INSERT INTO
posts (id, title)
VALUES
(1, 'Alpha'),
(2, 'Bravo'),
(3, 'Charlie'),
(4, 'Delta'),
(5, 'Echo');SQL
SELECT
id,
title
FROM
posts
ORDER BY
id
LIMIT
2
OFFSET
2;| id | title |
|---|---|
| 3 | Charlie |
| 4 | Delta |
Engine-specific syntax
Setup
CREATE TABLE posts (id INT, title VARCHAR(50));
INSERT INTO
posts (id, title)
VALUES
(1, 'Alpha'),
(2, 'Bravo'),
(3, 'Charlie'),
(4, 'Delta'),
(5, 'Echo');SQL
SELECT
id,
title
FROM
posts
ORDER BY
id
OFFSET
2 ROWS
FETCH NEXT
2 ROWS ONLY;| id | title |
|---|---|
| 3 | Charlie |
| 4 | Delta |
The page contents match, but the pagination syntax differs materially on SQL Server.