SQL Skipping then taking some results (Pagination)


Example

ISO/ANSI SQL:

SELECT Id, Col1
FROM TableName
ORDER BY Id
OFFSET 20 ROWS FETCH NEXT 20 ROWS ONLY;

MySQL:

SELECT * FROM TableName LIMIT 20, 20; -- offset, limit

Oracle; SQL Server:

SELECT Id,
   Col1
 FROM (SELECT Id,
           Col1,
           row_number() over (order by Id) RowNumber
      FROM TableName)
WHERE RowNumber BETWEEN 21 AND 40

PostgreSQL; SQLite:

SELECT * FROM TableName LIMIT 20 OFFSET 20;