Skip to content

Commit 96cb4a7

Browse files
committed
review suggestions
1 parent 184f0ee commit 96cb4a7

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

modules/ROOT/pages/queries/composed-queries/sequential-queries.adoc

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ NEXT
8585
In the following example, `NEXT` passes the variable `customer` to the second query:
8686

8787
.Passing a variable to another query via `NEXT`
88-
====
89-
.Query
9088
[source, cypher]
9189
----
9290
MATCH (c:Customer)-[:BUYS]->(:Product {name: 'Chocolate'})
@@ -108,12 +106,9 @@ RETURN customer.firstName AS chocolateCustomer
108106

109107
1+d|Rows: 3
110108
|===
111-
====
112109

113110

114111
.Passing multiple variables to another query via `NEXT`
115-
====
116-
.Query
117112
[source, cypher]
118113
----
119114
MATCH (c:Customer)-[:BUYS]->(p:Product {name: 'Chocolate'})
@@ -137,25 +132,23 @@ RETURN customer.firstName AS chocolateCustomer,
137132

138133
2+d|Rows: 3
139134
|===
140-
====
141135

142136
[NOTE]
143137
====
144138
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`.
145139
====
146140

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+
147143

148144
== Interactions with `CALL` subqueries
149145

150146
`NEXT` can serve as a more readable alternative to `CALL` subqueries.
151147

152-
[[call-subquery-rewrite]]
153-
.Rewriting a query with a `CALL` subquery
148+
[.tabbed-example]
154149
====
155-
[cols="1,1"]
156-
|===
157-
a|
158-
.`CALL` subquery
150+
[.include-with-CALL-subquery]
151+
======
159152
[source, cypher]
160153
----
161154
MATCH (p:Product)
@@ -165,8 +158,9 @@ CALL (p) {
165158
}
166159
RETURN p.name as product, customers
167160
----
168-
a|
169-
.`NEXT`
161+
======
162+
[.include-with-NEXT]
163+
======
170164
[source, cypher]
171165
----
172166
MATCH (p:Product)
@@ -181,7 +175,8 @@ NEXT
181175
182176
RETURN p.name as product, customers
183177
----
184-
|===
178+
======
179+
====
185180

186181
.Result
187182
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -195,12 +190,10 @@ RETURN p.name as product, customers
195190
| "Coffee" | ["Mateo", "Hannah", "Niko"]
196191
2+d|Rows: 5
197192
|===
198-
====
199193

200194
Even though the query which uses `NEXT` has more lines, it is divided into three segments which are easy to read.
201195
It also avoids the parentheses and indentation of the `CALL` subquery.
202196

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].
204197
[NOTE]
205198
====
206199
`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
209202

210203
== Interactions with conditional queries
211204

212-
[[next-and-conditional]]
213-
. Conditional queries in `NEXT`
214-
====
215-
.Query
205+
.Conditional queries in `NEXT`
216206
[source, cypher]
217207
----
218208
MATCH (c:Customer)-[:BUYS]->(:Product)<-[:SUPPLIES]-(s:Supplier)
@@ -252,7 +242,6 @@ ELSE
252242

253243
2+d|Rows: 7
254244
|===
255-
====
256245

257246
In the query above, customers are assigned personality types based on the products they purchased.
258247
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
262251

263252
== Interactions with `UNION` queries
264253

265-
[[next-and-union]]
266254
.`NEXT` in a query using `UNION`
267-
====
268-
.Query
269255
[source, cypher]
270256
----
271257
MATCH (c:Customer)-[:BUYS]->(:Product{name: "Laptop"})
@@ -294,7 +280,6 @@ RETURN customer AS customer, count(customer) as numberOfProducts
294280

295281
2+d|Rows: 6
296282
|===
297-
====
298283

299284
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.
300285
The use of `UNION ALL` added him to the list twice.

0 commit comments

Comments
 (0)