Back to the Couchbase homepageCouchbase logo
Couchbase Developer

  • Docs

    • Integrations
    • SDKs
    • Mobile SDKs

    • AI Developer
    • Backend
    • Full-stack
    • Mobile
    • Ops / DBA

    • Data Modeling
    • Scalability

  • Tutorials

    • Developer Community
    • Ambassador Program
  • Sign In
  • Try Free

N1QL and SQL++


N1QL

N1QL is Couchbase's implementation of theSQL++ query language(or "SQL for JSON"). It is SQL-89 compatible, which means that most of your SQL queries also work on N1QL:

SELECT t.relation COUNT(*) AS count, AVG(c.age) AS avg_age
                FROM  tutorial t
                UNNEST t.children c
                WHERE c.age > 10
                GROUP BY t.relation
                HAVING COUNT(*) > 1
                ORDER BY avg_age DESC
                LIMIT 1 OFFSET 1
Try the Online N1QL Tutorial

N1QL Index Advisor

The N1QL Index Advisor helps you to find the right index for your query. You can access it via the Web Console or try its online version:
...
                    "adviseinfo": {
                    "current_indexes": [
                      {
                        "index_statement": "CREATE PRIMARY INDEX #primary ON 'tutorial'",
                        "keyspace_alias": "tutorial_t"
                      }
                    ],
                    "recommended_indexes": {
                      "covering_indexes": [
                        {
                          "index_property": "GROUPBY & AGGREGATES pushdown",
                          "index_statement": "CREATE INDEX adv_ALL_children_age_relation ON 'tutorial'(ALL ARRAY 'c'.'age' FOR c IN 'children' END,'relation')",
                          "keyspace_alias": "tutorial_t"
                        }
                      ],
                    "indexes": [
                      {
                        "index_statement": "CREATE INDEX adv_ALL_children_age ON 'tutorial'(ALL ARRAY 'c'.'age' FOR c IN 'children' END)",
                        "keyspace_alias": "tutorial_t",
                        "recommending_rule": "Index keys follow order of predicate types: 1. leading array index for unnest."
                      }
                    ]
                    }
Go To Index Advisor
Download the N1QL Cheat Sheet  

N1QL Quick Reference Cards

N1QL


SELECT syntax | overview | grammar
JOIN syntax
INSERT | UPDATE | DELETE syntax
UPSERT | MERGE syntax
Data types
Operators
ANY, SOME, EVERY syntax
CASE, WHEN, THEN syntax
Functions
Arrayand Object functions
Dateand String functions
Type functions
User defined functions
Window functions andFunctions Overview
Subqueriesand Correlated Subqueries
CREATE INDEX syntax

N1QL for analytics


N1QL language reference for Analytics
Analytics expressions
Analytics query syntax anderrors
Analytics data definition language (DDL)
Analytics keywords
Analytics data types
Analytics builtin functions

Didn't find what you were looking for? Ask a question on Couchbase's Forum  

Featured Videos

Query Language Evolution

In this panel, Mike Carey, UC Irvine Bren Professor of Computer and Information Sciences and Don Chamberlin, Co-Inventor of SQL discuss about how query is evolving to adapt to modern database demands, and what role SQL++ will have in the future of hybrid operational/analytical computing.

CB110 - N1QL Online Course

This free tutorial training, comprised of numerous video tutorials, demonstrations, and hands on lab exercises, teaches how to index, select, filter, aggregate, and calculate JSON data fields, and how to insert, update upsert, join, and delete JSON documents, within a Couchbase data bucket.

N1QL+GSI: Language and Performance Improvements

Couchbase Server 5.0 has language and performance improvements for pagination, index exploitation, integration, index availability, and more. Couchbase Server 5.5 will offer even more language and performance features for N1QL and global secondary indexes (GSI), including ANSI joins, aggregate performance, index partitioning, auditing, and more. We’ll give you an overview of the new features as well as practical use case examples.

Introduction to SQL++ for Big Data: Same Language, More Power

Developer Advocate Matthew D. Groves talks about the history of SQL, its limitations and why SQL++ is necessary. This session is a gentle introduction to the key SQL++ concepts.

Testing N1QL workloads with Apache JMeter

In this short video you will learn how to stress test your N1QL workloads with Apache JMeter.

N1QL for Analytics: A Tutorial

The session provides a gentle introduction to N1QL for Analytics, the first commercial implementation of SQL++. We will cover the language features supported by the Couchbase Analytics Service and show you how easy it is for SQL users to transition to SQL++.

Couchbase home page link

3250 Olcott Street
Santa Clara, CA 95054
United States

  • company
  • about
  • leadership
  • news & press
  • investor relations
  • careers
  • events
  • legal
  • contact us
  • support
  • Developer portal
  • Documentation
  • Forums
  • PROFESSIONAL SERVICES
  • support login
  • support policy
  • training
  • quicklinks
  • blog
  • downloads
  • get started
  • resources
  • why nosql
  • pricing
  • follow us
  • Social Media Link for FacebookFacebook
  • Social Media Link for TwitterTwitter
  • Social Media Link for LinkedInLinkedIn
  • Social Media Link for Youtubeyoutube
  • Social Media Link for GitHubGithub
  • Social Media Link for Stack OverflowStack Overflow
  • Social Media Link for Discorddiscord

© 2025 Couchbase, Inc. Couchbase and the Couchbase logo are registered trademarks of Couchbase, Inc. All third party trademarks (including logos and icons) referenced by Couchbase, Inc. remain the property of their respective owners.

Terms of UsePrivacy PolicyCookie PolicySupport PolicyDo Not Sell My Personal InformationMarketing Preference Center