SQL
Paginate Results with OFFSET and LIMIT
Efficiently retrieve a subset of rows from a large dataset for pagination using OFFSET and LIMIT clauses, crucial for web application listings.
SELECT id, name, price
FROM products
ORDER BY created_at DESC
LIMIT 10 OFFSET 20;
How it works: This query demonstrates how to paginate results. The `LIMIT` clause specifies the maximum number of rows to return (e.g., 10 items per page). The `OFFSET` clause specifies the number of rows to skip before starting to return rows (e.g., skip the first 20 items to get the third page). This combination is essential for displaying large datasets page by page in web applications.