---
schema_version: "1"
id: eb712c01b8ba9e2c615ca38509ebb4405437c634a40a65c642583cb6f003d657
title: LIMIT, FETCH, and OFFSET Clauses
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/sql-commands/select-limit-offset.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/select-limit-offset.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 905a58a4dfc433c14bb39c1d66821e6d2742f85451715f160651e696e842847c
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `LIMIT`, `FETCH`, and `OFFSET` Clauses

## `LIMIT` and `OFFSET`

The `LIMIT` clause specifies the maximum number of rows to return. `<count>` specifies the maximum number of rows to return. The `LIMIT` clause consists of two independent subclauses, `LIMIT { <count> | ALL }` and `OFFSET <start>`. `<start>` specifies the number of rows to skip before starting to return rows.

If you use `LIMIT`, use an `ORDER BY` that uniquely orders results. Without `ORDER BY`, you get a random subset of the query’s rows.

If the `<count>` expression evaluates to NULL, it’s treated as `LIMIT ALL`. If `<start>` evaluates to NULL, it’s treated the same as `OFFSET 0`.

## `FETCH` and `OFFSET`

An alternative to `LIMIT` and `OFFSET` is `FETCH` and `OFFSET`.

```sql
OFFSET <start> {ROW | ROWS}
FETCH {FIRST | NEXT} [<count>] {ROW | ROWS} {ONLY | WITH TIES}
```

In this syntax, the `<start>` or `<count>` value is a literal constant, a parameter, or a variable name. The default `<count>` is 1. The `WITH TIES` option returns rows that tie for the last place in the result set.

**note:** For better pagination performance and consistency, use the Connect API `getSqlQueryRows` endpoint with `offset` and `rowLimit`. This approach reads row ranges from the result set without repeatedly querying your data set, reducing consumption costs. For more information, see [Query Best Practices](https://developer.salesforce.com/docs/data/data-cloud-query-guide/data-cloud-query-api-reference/query-services/c360a-api-queryservices-overview.md#best-practices).
