Skip to content

Commit 21e2903

Browse files
Added section on by-table semantics
1 parent 0697dbe commit 21e2903

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

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

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
`NEXT` has the following benefits:
99

1010
* `NEXT` can improve the modularity and readability of complex queries.
11-
* `NEXT` can be used instead of xref:subqueries/call-subquery.adoc[] and the xref:clauses/with.adoc[] clause to construct complex queries.
12-
* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] and xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries.
11+
* `NEXT` can be used instead of xref:clauses/with.adoc[] clause to construct complex queries.
12+
* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`]
13+
* `NEXT` allows for passing the full working table into xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries.
1314
1415
[[example-graph]]
1516
== Example graph
@@ -383,12 +384,42 @@ RETURN customer.firstName AS plantCustomer
383384
1+d|Rows: 6
384385
|===
385386

387+
=== Leveraging by-table semantics using `UNION` after `NEXT`
388+
If a `UNION` query follows a `NEXT` in any of its blocks, it will pass the full working table into all arms of the `UNION` query.
386389

387-
[[next-unsupported-behavior]]
388-
== Known limitations
390+
.By-table semantics using `NEXT`
391+
[source, cypher]
392+
----
393+
MATCH (c:Customer)-[:BUYS]->(p:Product)
394+
RETURN c, p
395+
396+
NEXT
389397
390-
`NEXT` currently does not support the following when they are used in a `UNION` query, wrapped in braces or after a `USE` clause:
398+
RETURN c.firstName AS name, COLLECT(p.price * c.discount) AS purchases, "discounted price" AS type
399+
UNION
400+
RETURN c.firstName AS name, COLLECT(p.price) AS purchases, "real price" AS type
391401
392-
* updating queries such as `CREATE` or `MERGE`,
393-
* `DISTINCT`,
394-
* aggregations.
402+
NEXT
403+
404+
RETURN * ORDER BY name, type
405+
----
406+
407+
.Result
408+
[role="queryresult",options="header,footer",cols="3*<m"]
409+
|===
410+
| name | purchases | type
411+
| Amir | [100.0, 0.5] | discounted price
412+
| Amir | [1000, 5] | real price
413+
| Hannah | [37.5, 1.5] | discounted price
414+
| Hannah | [250, 10] | real price
415+
| Keisha | [50.0] | discounted price
416+
| Keisha | [250] | real price
417+
| Leila | [100.0] | discounted price
418+
| Leila | [1000] | real price
419+
| Mateo | [50.0, 0.25, 0.5] | discounted price
420+
| Mateo | [1000, 5, 10] | real price
421+
| Niko | [125.0, 62.5, 2.5] | discounted price
422+
| Niko | [500, 250, 10] | real price
423+
| Yusuf | [100.0, 0.5] | discounted price
424+
| Yusuf | [1000, 5] | real price
425+
3+d|Rows: 14

0 commit comments

Comments
 (0)