title | titleSuffix | description | author | ms.author | ms.reviewer | ms.service | ms.subservice | ms.topic | ms.devlang | ms.date | ms.custom |
---|---|---|---|---|---|---|---|---|---|---|---|
MAX |
Azure Cosmos DB for NoSQL |
An Azure Cosmos DB for NoSQL system function that returns the maximum value. |
jcodella |
jacodel |
sidandrews |
cosmos-db |
nosql |
reference |
nosql |
02/27/2024 |
query-reference |
[!INCLUDENoSQL]
Returns the maximum of the values in the expression.
MAX(<scalar_expr>)
Description | |
---|---|
scalar_expr |
A scalar expression. |
Returns a numeric scalar value.
This example uses a container with multiple items that each have a /price
numeric field.
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/max/seed.json" range="1-2,4-8,10-14" highlight="3,8":::
For this example, the MAX
function is used in a query that includes the numeric field that was mentioned.
:::code language="nosql" source="~/cosmos-db-nosql-query-samples/scripts/max/query.sql" highlight="2":::
:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/max/result.json":::
- This function benefits from a range index.
- The arguments in
MAX
can be number, string, boolean, or null. - Any
undefined
values are ignored. - The following priority order is used (in descending order), when comparing different types of data:
- string
- number
- boolean
- null