
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou can get all unique type names from your dataset using GROQ with a query like this:
array::unique(*[]._type)This works by:
*[] - Fetches all documents._type - Extracts just the _type field from each document (returns an array of type names)array::unique() - Removes duplicates from the arrayThis is essentially the GROQ equivalent of SQL's "SELECT DISTINCT". The result will be an array of all unique document type names in your dataset.
Alternative approaches:
If you want more control or additional information, you could also use:
// Get types with document counts
{
"types": array::unique(*[]._type)
}Or if you want to see the types in a more structured way with counts:
*[] {
"type": _type
} | order(type) | {"types": array::unique(@.type)}You can test these queries in:
The array::unique() function is specifically designed for this kind of operation and is the most straightforward way to get distinct values in GROQ, similar to SQL's SELECT DISTINCT.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store