SQL OFFSET-FETCH Clause
- OFFSET excludes the first set of records.
- OFFSET can only be used with an ORDER BY clause.
- OFFSET with FETCH NEXT returns a defined window of records.
- OFFSET with FETCH NEXT is great for building pagination support.
The SQL ORDER BY OFFSET syntax
The general syntax to exclude first n records is:
- SELECT column-names FROM table-name ORDER BY column-names OFFSET n ROWS
To exclude first n records and return only the next m records:
- SELECT column-names FROM table-name ORDER BY column-names OFFSET n ROWS FETCH NEXT m ROWS ONLY
This will return only record (n + 1) to (n + 1 + m). See example below.
Comments
Post a Comment