Skip to content

Commit 5c5abfc

Browse files
committed
Update OFFSET LIMIT NoSQL query article
1 parent 92dc049 commit 5c5abfc

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,73 @@
11
---
22
title: OFFSET LIMIT
33
titleSuffix: Azure Cosmos DB for NoSQL
4-
description: An Azure Cosmos DB for NoSQL clause that skips and takes a specified number of results.
4+
description: An Azure Cosmos DB for NoSQL query clause with two keywords that skips and/or takes a specified number of results.
55
author: jcodella
66
ms.author: jacodel
77
ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: nosql
1010
ms.topic: reference
1111
ms.devlang: nosql
12-
ms.date: 02/27/2024
12+
ms.date: 07/08/2024
1313
ms.custom: query-reference
1414
---
1515

1616
# OFFSET LIMIT (NoSQL query)
1717

1818
[!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)]
1919

20-
The ``OFFSET LIMIT`` clause is an optional clause to **skip** and then **take** some number of values from the query. The ``OFFSET`` count and the ``LIMIT`` count are required in the OFFSET LIMIT clause.
20+
The `OFFSET LIMIT` clause is an optional clause to **skip** and then **take** some number of values from the query. The `OFFSET` count and the `LIMIT` count are required in the OFFSET LIMIT clause.
2121

22-
When ``OFFSET LIMIT`` is used with an ``ORDER BY`` clause, the result set is produced by doing skip and take on the ordered values. If no ``ORDER BY`` clause is used, it results in a deterministic order of values.
22+
When `OFFSET LIMIT` is used with an `ORDER BY` clause, the result set is produced by doing skip and take on the ordered values. If no `ORDER BY` clause is used, it results in a deterministic order of values.
2323

2424
## Syntax
2525

2626
```nosql
2727
OFFSET <offset_amount> LIMIT <limit_amount>
28-
```
28+
```
2929

3030
## Arguments
3131

3232
| | Description |
3333
| --- | --- |
34-
| **``<offset_amount>``** | Specifies the integer number of items that the query results should skip. |
35-
| **``<limit_amount>``** | Specifies the integer number of items that the query results should include. |
34+
| **`<offset_amount>`** | Specifies the integer number of items that the query results should skip. |
35+
| **`<limit_amount>`** | Specifies the integer number of items that the query results should include. |
3636

3737
## Examples
3838

39-
For the example in this section, this reference set of items is used. Each item includes a ``name`` property.
39+
For the example in this section, this reference set of items is used. Each item includes a `name` property.
4040

41-
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit/seed.json" range="1-2,4-7,9-12,14-17,19-22,24-27" highlight="3,6,9,12,15":::
41+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit/seed.json" range="1-2,4-7,9-12,14-17,19-22,24-27" highlight="3,7,11,15,19":::
4242

43-
This example includes a query using the ``OFFSET LIMIT`` clause to return a subset of the matching items by skipping **one** item and taking the next **three**.
43+
> [!NOTE]
44+
> In the original JSON data, the items are not sorted.
45+
46+
The first example includes a query that returns only the `name` property from all items sorted in alphabetical order.
47+
48+
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit-none/query.sql":::
49+
50+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit-none/result.json":::
51+
52+
This next example includes a query using the `OFFSET LIMIT` clause to skip the first item. The limit is set to the number of items in the container to return all possible remaining values. In this example, the query skips **one** item, and returns the remaining **four** (out of a limit of five).
53+
54+
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit-partial/query.sql" highlight="10":::
55+
56+
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit-partial/result.json":::
57+
58+
This final example includes a query using the `OFFSET LIMIT` clause to return a subset of the matching items by skipping **one** item and taking the next **three**.
4459

4560
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit/query.sql" highlight="10":::
4661

4762
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/offset-limit/result.json":::
4863

4964
## Remarks
5065

51-
- Both the ``OFFSET`` count and the ``LIMIT`` count are required in the ``OFFSET LIMIT`` clause. If an optional ``ORDER BY`` clause is used, the result set is produced by doing the skip over the ordered values. Otherwise, the query returns a fixed order of values.
52-
- The RU charge of a query with ``OFFSET LIMIT`` increases as the number of terms being offset increases. For queries that have [multiple pages of results](pagination.md), we typically recommend using [continuation tokens](pagination.md#continuation-tokens). Continuation tokens are a "bookmark" for the place where the query can later resume. If you use ``OFFSET LIMIT``, there's no "bookmark." If you wanted to return the query's next page, you would have to start from the beginning.
53-
- You should use ``OFFSET LIMIT`` for cases when you would like to skip items entirely and save client resources. For example, you should use ``OFFSET LIMIT`` if you want to skip to the 1000th query result and have no need to view results 1 through 999. On the backend, ``OFFSET LIMIT`` still loads each item, including those items that are skipped. The performance advantage is measured in reducing client resources by avoiding processing items that aren't needed.
66+
- Both the `OFFSET` count and the `LIMIT` count are required in the `OFFSET LIMIT` clause. If an optional `ORDER BY` clause is used, the result set is produced by doing the skip over the ordered values. Otherwise, the query returns a fixed order of values.
67+
- The RU charge of a query with `OFFSET LIMIT` increases as the number of terms being offset increases. For queries that have [multiple pages of results](pagination.md), we typically recommend using [continuation tokens](pagination.md#continuation-tokens). Continuation tokens are a "bookmark" for the place where the query can later resume. If you use `OFFSET LIMIT`, there's no "bookmark." If you wanted to return the query's next page, you would have to start from the beginning.
68+
- You should use `OFFSET LIMIT` for cases when you would like to skip items entirely and save client resources. For example, you should use `OFFSET LIMIT` if you want to skip to the 1000th query result and have no need to view results 1 through 999. On the backend, `OFFSET LIMIT` still loads each item, including those items that are skipped. The performance advantage is measured in reducing client resources by avoiding processing items that aren't needed.
5469

5570
## Related content
5671

57-
- [``GROUP BY`` clause](group-by.md)
58-
- [``ORDER BY`` clause](order-by.md)
72+
- [`GROUP BY` clause](group-by.md)
73+
- [`ORDER BY` clause](order-by.md)

0 commit comments

Comments
 (0)