Skip/Offset Rows from Table Data Result in SQL Server/ Postgres / Pagination
Skip/Offset Rows from Table Data Result in SQL Server/ Postgres
this is most helpful in pagination of data
SELECT col1, col2, ... FROM ...
WHERE ...
ORDER BY -- this is a MUST there must be ORDER BY statement
-- the paging comes here
OFFSET 10 ROWS -- skip 10 rows
FETCH NEXT 10 ROWS ONLY; -- take 10 rows
If we want to skip ORDER BY we can use
SELECT col1, col2, ...
...
ORDER BY CURRENT_TIMESTAMP
OFFSET 10 ROWS -- skip 10 rows
FETCH NEXT 10 ROWS ONLY; -- take 10 rows
Comments
Post a Comment