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: modules/ROOT/pages/queries/composed-queries/sequential-queries.adoc
+11-26Lines changed: 11 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,8 +85,6 @@ NEXT
85
85
In the following example, `NEXT` passes the variable `customer` to the second query:
86
86
87
87
.Passing a variable to another query via `NEXT`
88
-
====
89
-
.Query
90
88
[source, cypher]
91
89
----
92
90
MATCH (c:Customer)-[:BUYS]->(:Product {name: 'Chocolate'})
@@ -108,12 +106,9 @@ RETURN customer.firstName AS chocolateCustomer
108
106
109
107
1+d|Rows: 3
110
108
|===
111
-
====
112
109
113
110
114
111
.Passing multiple variables to another query via `NEXT`
115
-
====
116
-
.Query
117
112
[source, cypher]
118
113
----
119
114
MATCH (c:Customer)-[:BUYS]->(p:Product {name: 'Chocolate'})
@@ -137,25 +132,23 @@ RETURN customer.firstName AS chocolateCustomer,
137
132
138
133
2+d|Rows: 3
139
134
|===
140
-
====
141
135
142
136
[NOTE]
143
137
====
144
138
When followed by a `NEXT` clause, expressions in a `RETURN` clause must either be variables that have been introduced before or they must be aliased with `AS`.
145
139
====
146
140
141
+
Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`. This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope].
142
+
147
143
148
144
== Interactions with `CALL` subqueries
149
145
150
146
`NEXT` can serve as a more readable alternative to `CALL` subqueries.
@@ -195,12 +190,10 @@ RETURN p.name as product, customers
195
190
| "Coffee" | ["Mateo", "Hannah", "Niko"]
196
191
2+d|Rows: 5
197
192
|===
198
-
====
199
193
200
194
Even though the query which uses `NEXT` has more lines, it is divided into three segments which are easy to read.
201
195
It also avoids the parentheses and indentation of the `CALL` subquery.
202
196
203
-
Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`. This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope].
204
197
[NOTE]
205
198
====
206
199
`NEXT` cannot be used inside a `CALL` subquery that uses the (deprecated) xref:subqueries/call-subquery.adoc#importing-with[importing `WITH`] syntax.
@@ -209,10 +202,7 @@ Variables which are local to a query and which are not explicitly returned are n
209
202
210
203
== Interactions with conditional queries
211
204
212
-
[[next-and-conditional]]
213
-
. Conditional queries in `NEXT`
214
-
====
215
-
.Query
205
+
.Conditional queries in `NEXT`
216
206
[source, cypher]
217
207
----
218
208
MATCH (c:Customer)-[:BUYS]->(:Product)<-[:SUPPLIES]-(s:Supplier)
@@ -252,7 +242,6 @@ ELSE
252
242
253
243
2+d|Rows: 7
254
244
|===
255
-
====
256
245
257
246
In the query above, customers are assigned personality types based on the products they purchased.
258
247
The second query is a conditional query that returns different base personality types for different suppliers the customers purchased from.
@@ -262,10 +251,7 @@ Finally, the fourth query is another conditional query which subsumes multiple b
262
251
263
252
== Interactions with `UNION` queries
264
253
265
-
[[next-and-union]]
266
254
.`NEXT` in a query using `UNION`
267
-
====
268
-
.Query
269
255
[source, cypher]
270
256
----
271
257
MATCH (c:Customer)-[:BUYS]->(:Product{name: "Laptop"})
@@ -294,7 +280,6 @@ RETURN customer AS customer, count(customer) as numberOfProducts
294
280
295
281
2+d|Rows: 6
296
282
|===
297
-
====
298
283
299
284
In this example, the list of customer names from the first query has a duplicate entry for "Mateo" who bought both a laptop and coffee.
300
285
The use of `UNION ALL` added him to the list twice.
0 commit comments