Share via


DISTINCT - Query language in Cosmos DB (in Azure and Fabric)

The DISTINCT keyword eliminates duplicates in the projected query results.

In this example, the query projects values for each product category. If two categories are equivalent, only a single occurrence returns in the results.

SELECT DISTINCT VALUE
    p.category
FROM
    products p
[
  "Accessories",
  "Tools"
]

You can also project values even if the target field doesn't exist. In this case, the field doesn't exist in one of the items, so the query returns an empty object for that specific unique value.

SELECT DISTINCT
    p.category
FROM
    products p

The results are:

[
  {},
  {
    "category": "Accessories"
  },
  {
    "category": "Tools"
  }
]