Search:

Search all manuals
Search this manual
Manual
Couchbase Server Manual 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Developer Guide 2.0
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
9 Views and Indexes
Chapter Sections
Chapters

9.10. Translating SQL to Map/Reduce

9.10.1. Translating SQL Field Selection (SELECT) to Map/Reduce
9.10.2. Translating SQL WHERE to Map/Reduce
9.10.3. Translating SQL ORDER BY to Map/Reduce
9.10.4. Translating SQL GROUP BY to Map/Reduce
9.10.5. Translating SQL LIMIT and OFFSET
SELECT fieldlist FROM table \
    WHERE condition \
    GROUP BY groupfield \
    ORDER BY orderfield \
    LIMIT limitcount OFFSET offsetcount

The different elements within the source statement affect how a view is written in the following ways:

The interaction between the view map() function, reduce() function, selection parameters and other miscellaneous parameters according to the table below:

SQL Statement FragmentView KeyView Valuemap() Functionreduce() FunctionSelection ParametersOther Parameters
SELECT fieldsYesYesYesNo: with GROUP BY and SUM() or COUNT() functions onlyNoNo
FROM tableNoNoYesNoNoNo
WHERE clauseYesNoYesNoYesNo
ORDER BY fieldYesNoYesNoNodescending
LIMIT x OFFSET yNoNoNoNoNolimit, skip
GROUP BY fieldYesYesYesYesNoNo

Within SQL, the basic query structure can be used for a multitude of different queries. For example, the same 'SELECT fieldlist FROM table WHERE xxxx can be used with a number of different clauses.

Within map/reduce and Couchbase Server, multiple views may be needed to be created to handled different query types. For example, performing a query on all the blog posts on a specific date will need a very different view definition than one needed to support selection by the author.