A newer version of this documentation is available.

View Latest

SELECT statement

SELECT statements let you retrieve data from specified keyspaces. A simple query in N1QL has three parts to it:

  • SELECT - Parts of the document to return in an array.

  • FROM - The keyspace, or datastore with which to work.

  • WHERE - Conditions the data must satisfy to be retrieved.

Only a SELECT clause is required in a query.

Because the data is stored in documents rather than rigidly structured tables, queries can return a collection of different document structures or fragments. The one requirement is that the retrieved data will match the conditions in the WHERE clause, if one is provided.

Exercising the full power of the SELECT statement is more complex. With the SELECT statement, you can retrieve any data from a keyspace. Once retrieved you can specify how you want the data returned. You can also manipulate the data in the result set, and, using data manipulation statements, you can modify the data in the actual keyspace.