Difference between SQL and N1QL?
Difference between SQL and N1QL?
SQL
SQL (Structured Query Language) is the standard language for managing and querying relational databases like MySQL, PostgreSQL, or SQL Server. It’s designed around tables, rows, and columns, and it uses a fairly uniform syntax to perform operations like SELECT, INSERT, UPDATE, and DELETE.
N1QL
N1QL (Non-First Normal Form Query Language) is specific to Couchbase and is basically SQL-like syntax for querying JSON documents. It lets you do things that feel very familiar if you know SQL, but it also includes extensions that handle the hierarchical and flexible nature of JSON data. For example, you can navigate nested objects, arrays, and perform operations that aren’t typically needed in a relational world.
N1QL is specifically designed for Couchbase, so it’s pretty tightly coupled to that platform. In other words, you wouldn’t use N1QL to directly interact with a different database system like MongoDB, PostgreSQL, or MySQL.
Each database usually has its own query language or dialect. For instance, MongoDB has its own query language, and relational databases use SQL. So N1QL is pretty much Couchbase’s own flavor of a SQL-like language, specialized for working with JSON documents in that ecosystem.
Example N1QL query
Here is an example N1QL query to know the version of the Couchbase server that you’re currently running.
SELECT VERSION() AS couchbase_version;