Page History
...
WHERE managerName.first = 'Joe'
Info |
---|
Due to limitation of the Mongo API, when comparing two fields in the WHERE filter, only integer, double, string, boolean, and code data types work correctly. |
Conditions:
condition AND condition
condition && condition
condition OR condition
condition || condition
CONTAINS_ALL ('value','value',...)
CONTAINS_ALL ( 2011, 2012, 2013,... )
NOT condition
expr IS [NOT] NULL
expr [=|>=|>|<=|<|<>|!=] predicate
expr [NOT] IN (subquery)
expr [NOT] IN (value [, value] ...)
expr [NOT] BETWEEN expr AND expr
expr [NOT] BETWEEN (subquery) AND (subquery)
expr [NOT] LIKE like_expr ESCAPE escape_char
...
expr | expr
expr & expr
expr << expr
expr >> expr
expr + expr
expr – expr
expr * expr
expr / expr
expr % expr
Info |
---|
Math expressions ( + , - , *, / , % ) are supported on SELECT fields ( e.g. select itemID + prodID from NewItems ) and inside WHERE filters (e.g. select * from NewItems where itemID + prodID < 1000 ). |
Because both standard SQL and JSON objects are supported, both parentheses () and square brackets [] can be used to specify the IN condition. Either of these will work:
SELECT * FROM baseball WHERE city IN ['Chicago','New York']
SELECT * FROM baseball WHERE city IN ('Chicago','New York')
Example
Code Block |
---|
SELECT *
FROM zips
WHERE city LIKE 'KE%'
AND pop > 2000 |
...
The GROUP BY clause is used in combination with aggregate functions to group the results by one or more documents.
Example
Code Block |
---|
SELECT city
FROM zips
WHERE pop > 100000
GROUP BY state |
Info |
---|
Each document can have a different set of fields in MongoDB. This is very different from a RDBMS where a table has a defined set of columns and each record has the same set of columns. In MongoDB, a field may exist for one record but not for another record. A WHERE filter can cause some fields to become non-existing. Our implementation of MongoSQL is limited by the behaviors of MongoDB. Consider this example: |
HAVING clause
Used in conjunction with GROUP BY, allows retreiving a subset of an aggregate function.
Info |
---|
On an aggregate SELECT query (i.e. when the GROUP BY clause is present), the WHERE clause filters the documents before performing the GROUP BY operation while the HAVING clause filters the result set after the aggregation step. In the WHERE clause, the collection's field names are used when processing the WHERE filters. However, the field names specified in the HAVING clause are matched with the alias names specified in the SELECT fields first when processing the HAVING filters. |
Example
Code Block |
---|
SELECT city, SUM(pop) AS pop
FROM zips
GROUP BY city
HAVING pop > 30000 |
ORDER BY clause
ORDER BY is used to sort the result set by a specified field and sorts in ascending order by default. Sorting by descending order can be done with the use of DESC.
Info |
---|
ORDER BY columnIndex cannot be used with a SELECT * query. This limitation occurs because the $sort operator from MongoDB's Aggregation Framework requires a field name argument for the order-key parameter. |
Example
Code Block |
---|
SELECT city, state
FROM zips
WHERE pop > 50000
ORDER BY state |
LIMIT and OFFSET clause
LIMIT restricts the number of documents returned by the SELECT statement. OFFSET indicates the offset of the first document to return.
Example
Code Block |
---|
SELECT city
FROM zips LIMIT 10
GO
SELECT city
FROM zips LIMIT 10 OFFSET 5
GO |
...
Info |
---|
LIMIT and OFFSET apply to the documents being queried, not to the flattened records when the FLATTEN_ARRAY option is used. |
Back to top
UNION | UNION ALL | INTERSECT | EXCEPT clause
...
UNION can be used to combine the result sets of two or more SELECT statements.
Example
Code Block |
---|
SELECT dodad
FROM newproduct
UNION
SELECT dodad
FROM newproductclone
GO |
Info |
---|
UNION clauses can be very CPU and RAM intensive because the resulting documents are compared and selected on the client side within Aqua Data Studio. Out of Memory Exceptions can occur if extremely large amounts of documents are compared and selected. See our Memory Configuration page on how to increase the RAM Aqua Data Studio uses. |
Info |
---|
Nested UNION, EXCEPT, and INTERSECT are not supported. |
UNION ALL
UNION ALL can be used to combine the result sets of two or more SELECT statements and will include duplicate rows.
...