You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-query-from.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,17 @@ description: Learn about the SQL syntax, and example for FROM clause for Azure C
4
4
author: timsander1
5
5
ms.service: cosmos-db
6
6
ms.topic: conceptual
7
-
ms.date: 12/02/2019
7
+
ms.date: 05/08/2020
8
8
ms.author: tisande
9
9
10
10
---
11
11
# FROM clause in Azure Cosmos DB
12
12
13
13
The FROM (`FROM <from_specification>`) clause is optional, unless the source is filtered or projected later in the query. A query like `SELECT * FROM Families` enumerates over the entire `Families` container. You can also use the special identifier ROOT for the container instead of using the container name.
14
14
15
-
The FROM clause enforces the following rules per query:
15
+
The `FROM` clause enforces the following rules per query:
16
16
17
-
* The container can be aliased, such as `SELECT f.id FROM Families AS f` or simply `SELECT f.id FROM Families f`. Here `f` is the alias for `Families`. AS is an optional keyword to [alias](sql-query-aliasing.md) the identifier.
17
+
* The container can be aliased, such as `SELECT f.id FROM Families AS f` or simply `SELECT f.id FROM Families f`. Here `f` is the alias for `Families`. AS is an optional keyword to [alias](sql-query-working-with-json.md#aliasing) the identifier.
18
18
19
19
* Once aliased, the original source name cannot be bound. For example, `SELECT Families.id FROM Families f` is syntactically invalid because the identifier `Families` has been aliased and can't be resolved anymore.
20
20
@@ -25,15 +25,15 @@ The FROM clause enforces the following rules per query:
25
25
```sql
26
26
FROM<from_specification>
27
27
28
-
<from_specification> ::=
28
+
<from_specification> ::=
29
29
<from_source> {[ JOIN<from_source>][,...n]}
30
30
31
-
<from_source> ::=
31
+
<from_source> ::=
32
32
<container_expression> [[AS] input_alias]
33
33
| input_alias IN<container_expression>
34
34
35
-
<container_expression> ::=
36
-
ROOT
35
+
<container_expression> ::=
36
+
ROOT
37
37
| container_name
38
38
| input_alias
39
39
| <container_expression>'.' property_name
@@ -46,9 +46,9 @@ FROM <from_specification>
46
46
47
47
Specifies a data source, with or without an alias. If alias is not specified, it will be inferred from the `<container_expression>` using following rules:
48
48
49
-
- If the expression is a container_name, then container_name will be used as an alias.
49
+
- If the expression is a container_name, then container_name will be used as an alias.
50
50
51
-
- If the expression is `<container_expression>`, then property_name, then property_name will be used as an alias. If the expression is a container_name, then container_name will be used as an alias.
51
+
- If the expression is `<container_expression>`, then property_name, then property_name will be used as an alias. If the expression is a container_name, then container_name will be used as an alias.
52
52
53
53
- AS `input_alias`
54
54
@@ -94,9 +94,9 @@ If a container expression accesses properties or array elements and that value d
94
94
95
95
A container expression may be container-scoped or document-scoped:
96
96
97
-
-An expression is container-scoped, if the underlying source of the container expression is either ROOT or `container_name`. Such an expression represents a set of documents retrieved from the container directly, and is not dependent on the processing of other container expressions.
97
+
- An expression is container-scoped, if the underlying source of the container expression is either ROOT or `container_name`. Such an expression represents a set of documents retrieved from the container directly, and is not dependent on the processing of other container expressions.
98
98
99
-
-An expression is document-scoped, if the underlying source of the container expression is `input_alias` introduced earlier in the query. Such an expression represents a set of documents obtained by evaluating the container expression in the scope of each document belonging to the set associated with the aliased container. The resulting set will be a union of sets obtained by evaluating the container expression for each of the documents in the underlying set.
99
+
- An expression is document-scoped, if the underlying source of the container expression is `input_alias` introduced earlier in the query. Such an expression represents a set of documents obtained by evaluating the container expression in the scope of each document belonging to the set associated with the aliased container. The resulting set will be a union of sets obtained by evaluating the container expression for each of the documents in the underlying set.
100
100
101
101
## Examples
102
102
@@ -142,7 +142,7 @@ The results are:
142
142
]
143
143
```
144
144
145
-
The preceding query used an array as the source, but you can also use an object as the source. The query considers any valid, defined JSON value in the source for inclusion in the result. The following example would exclude `Families` that don’t have an `address.state` value.
145
+
The preceding query used an array as the source, but you can also use an object as the source. The query considers any valid, defined JSON value in the source for inclusion in the result. The following example would exclude `Families` that don't have an `address.state` value.
Copy file name to clipboardExpand all lines: articles/cosmos-db/sql-query-select.md
+9-126Lines changed: 9 additions & 126 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,29 @@
1
1
---
2
2
title: SELECT clause in Azure Cosmos DB
3
3
description: Learn about SQL SELECT clause for Azure Cosmos DB. Use SQL as an Azure Cosmos DB JSON query language.
4
-
author: ginarobinson
4
+
author: timsander1
5
5
ms.service: cosmos-db
6
6
ms.topic: conceptual
7
-
ms.date: 06/10/2019
8
-
ms.author: girobins
7
+
ms.date: 05/08/2020
8
+
ms.author: tisande
9
9
---
10
10
11
11
# SELECT clause in Azure Cosmos DB
12
12
13
-
Every query consists of a SELECT clause and optional [FROM](sql-query-from.md) and [WHERE](sql-query-where.md) clauses, per ANSI SQL standards. Typically, the source in the FROM clause is enumerated, and the WHERE clause applies a filter on the source to retrieve a subset of JSON items. The SELECT clause then projects the requested JSON values in the select list.
13
+
Every query consists of a `SELECT` clause and optional [FROM](sql-query-from.md) and [WHERE](sql-query-where.md) clauses, per ANSI SQL standards. Typically, the source in the `FROM` clause is enumerated, and the `WHERE` clause applies a filter on the source to retrieve a subset of JSON items. The `SELECT` clause then projects the requested JSON values in the select list.
14
14
15
15
## Syntax
16
16
17
17
```sql
18
18
SELECT<select_specification>
19
19
20
-
<select_specification> ::=
21
-
'*'
22
-
| [DISTINCT] <object_property_list>
20
+
<select_specification> ::=
21
+
'*'
22
+
| [DISTINCT] <object_property_list>
23
23
| [DISTINCT] VALUE <scalar_expression> [[ AS ] value_alias]
Specifies that the JSON value should be retrieved instead of the complete JSON object. This, unlike `<property_list>` does not wrap the projected value in an object.
47
-
46
+
48
47
-`DISTINCT`
49
48
50
49
Specifies that duplicates of projected properties should be removed.
@@ -93,122 +92,6 @@ The results are:
93
92
}]
94
93
```
95
94
96
-
### Quoted property accessor
97
-
You can access properties using the quoted property operator []. For example, `SELECT c.grade` and `SELECT c["grade"]` are equivalent. This syntax is useful to escape a property that contains spaces, special characters, or has the same name as a SQL keyword or reserved word.
98
-
99
-
```sql
100
-
SELECT f["lastName"]
101
-
FROM Families f
102
-
WHERE f["id"] ="AndersenFamily"
103
-
```
104
-
105
-
### Nested properties
106
-
107
-
The following example projects two nested properties, `f.address.state` and `f.address.city`.
108
-
109
-
```sql
110
-
SELECTf.address.state, f.address.city
111
-
FROM Families f
112
-
WHEREf.id="AndersenFamily"
113
-
```
114
-
115
-
The results are:
116
-
117
-
```json
118
-
[{
119
-
"state": "WA",
120
-
"city": "Seattle"
121
-
}]
122
-
```
123
-
### JSON expressions
124
-
125
-
Projection also supports JSON expressions, as shown in the following example:
In the preceding example, the SELECT clause needs to create a JSON object, and since the sample provides no key, the clause uses the implicit argument variable name `$1`. The following query returns two implicit argument variables: `$1` and `$2`.
If your data contains properties with the same names as reserved keywords such as "order" or "Group" then the queries against these documents will result in syntax errors. You should explicitly include the property in `[]` character to run the query successfully.
170
-
171
-
For example, here's a document with a property named `order` and a property `price($)` that contains special characters:
172
-
173
-
```json
174
-
{
175
-
"id": "AndersenFamily",
176
-
"order": [
177
-
{
178
-
"orderId": "12345",
179
-
"productId": "A17849",
180
-
"price($)": 59.33
181
-
}
182
-
],
183
-
"creationDate": 1431620472,
184
-
"isRegistered": true
185
-
}
186
-
```
187
-
188
-
If you run a queries that includes the `order` property or `price($)` property, you will receive a syntax error.
0 commit comments