GROQ (Graph-Relational Object Queries) is a query language for JSON documents, designed and maintained by Sanity CMS. It lets you filter, sort, join, and project structured content using a compact, readable syntax — no SQL or GraphQL required.
Last updated: June 2026
What Is GROQ?¶
GROQ is to Sanity what SQL is to relational databases and GraphQL is to API-driven applications. It is a native query language for querying, filtering, joining, and transforming JSON documents stored in a Sanity content lake.
Unlike SQL, GROQ handles deeply nested JSON naturally. Unlike GraphQL, GROQ does not require a schema to query — you write filters and projections directly.
Basic GROQ Query Syntax¶
Filter by Document Type¶
Every GROQ query typically starts by filtering documents of a specific type.
This returns all documents where _type equals "post".
Add Field Conditions¶
Chain additional conditions with logical operators.
Project Specific Fields¶
Use curly braces to control which fields the query returns.
Sorting and Ordering¶
Sort results with the order() function. Default order is by _createdAt.
Pagination¶
GROQ uses slice syntax for pagination — no cursors required.
Reference Resolution¶
The -> operator resolves document references inline — GROQ's equivalent of a JOIN.
This resolves the author reference field to the referenced document's name field in a single query — no separate API calls needed.
Advanced GROQ Patterns¶
Count Documents¶
Select with Conditional Logic¶
Global Object References¶
Filter by Reference¶
Build Better Apps With Reinvoice¶
Running a SaaS? Reinvoice handles invoicing, subscription management, and billing automations so you can focus on code. Start your free trial .
Frequently Asked Questions¶
Is GROQ faster than GraphQL?
GROQ queries run natively in Sanity's content lake without a separate API server. For Sanity projects, GROQ is typically faster because it avoids the GraphQL middleware layer.
Can GROQ do joins?
Yes. The -> operator resolves document references inline, similar to a SQL JOIN. It can traverse multiple levels: author->company->name.
How do I paginate GROQ queries?
Use slice syntax [start...end]. Page 1: [0...20], Page 2: [20...40]. Combine with | order() for consistent ordering across pages.
What is the difference between GROQ and GraphQL?
GROQ is a query language for JSON documents designed by Sanity. GraphQL is a query language for APIs. GROQ runs directly on the content lake; GraphQL requires a resolver layer.
Can I use GROQ with other databases?
GROQ is designed for Sanity's content lake. Other databases have their own query languages (SQL, MongoDB aggregation pipeline, etc.) that serve similar purposes with different syntax.

