> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Limit Query Results

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `LIMIT` and `OFFSET` clauses restrict the operation of:

* A <InternalLink path="selection-queries">selection query</InternalLink>, including when it occurs as part of <InternalLink path="insert">`INSERT`</InternalLink> or <InternalLink path="upsert">`UPSERT`</InternalLink>.
* <InternalLink path="update">`UPDATE`</InternalLink> and <InternalLink path="delete">`DELETE`</InternalLink> statements.

`OFFSET` instructs the operation to skip a specified number of rows. It is often used in conjunction with `LIMIT` to "paginate" through retrieved rows.

<Danger>
  Using `LIMIT`/`OFFSET` to implement pagination can be very slow for large tables. We recommend using <InternalLink path="pagination">keyset pagination</InternalLink> instead.
</Danger>

## Syntax

### LIMIT

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
LIMIT { <limit_value> | ALL }
```

For PostgreSQL compatibility, CockroachDB also supports `FETCH FIRST limit_value ROWS ONLY` and `FETCH NEXT limit_value ROWS ONLY` as aliases for `LIMIT`. If `limit_value` is omitted, then one row is fetched.

### OFFSET

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
OFFSET <offset_value> [ ROW | ROWS ]
```

## Examples

For example uses with `SELECT`, see <InternalLink path="selection-queries#limit-row-count">Limit Row Count</InternalLink>.

## See also

* <InternalLink path="delete">`DELETE`</InternalLink>
* <InternalLink path="delete">`UPDATE`</InternalLink>
* <InternalLink path="insert">`INSERT`</InternalLink>
* <InternalLink path="upsert">`UPSERT`</InternalLink>
* <InternalLink path="selection-queries">Selection Queries</InternalLink>
