# `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](/docs/data/data-cloud-query-guide/references/data-cloud-query-api-reference/c360a-api-queryservices-overview.md#best-practices).
:::
