Most N1QL queries will be in the following format:
SELECT [DISTINCT] <expression> FROM <data source> WHERE <expression> GROUP BY <expression> ORDER BY <expression> LIMIT <number> OFFSET <number>
The preceding statement is very generic. It tells you the comprehensive options provided by N1QL in one statement. Let me break it down into parts so that it can be understood easily.
I will be explaining these N1QL query syntax based on documents stored in the bucket, LearningCouchbase
, which we created earlier. If you remember correctly, we have already entered some documents in the LearningCouchbase
bucket as well. We will execute the N1QL queries only on those documents.
If we want to fetch all the users' documents in the LearningCouchbase
bucket, but want to display only some information or attributes, that is, the name and the book attribute of the documents, it can be done as follows:
SELECT name,book FROM LearningCouchbase...