Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.62 KB

File metadata and controls

64 lines (45 loc) · 1.62 KB
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

MAX (NoSQL query)

[!INCLUDENoSQL]

Returns the maximum of the values in the expression.

Syntax

MAX(<scalar_expr>)  

Arguments

Description
scalar_expr A scalar expression.

Return types

Returns a numeric scalar value.

Examples

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":::

Remarks

  • 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:
    1. string
    2. number
    3. boolean
    4. null

Related content