OFFSET CLAUSE

Offset is a power tool in SQL that is used to skip a specific number of rows from query results.

USE CASES

  • skipping unwanted data
  • Pagination: can divide large datasets into manageable chunks to display
  • Dynamic Data Exploration: you can skip parts of the data and only analyse certain areas.

EXAMPLE

Although it’s possible to use offset without an order-by clause, it does not make much sense to do so. This is because without an order-by, results are returned in a random order, so the subset of results skipped will be different each time the query is run.

BASIC USAGE

Example 2: using offset and fetch

OFFSET with DISTINCT and GROUP BY

This skips the first 5 rows and then gives the next 5 rows.

OFFSET WITH JOINS

FIND OUT MORE ABOUT FETCH

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top