From ee6a5d9d725f871312a0ccf0819a5e1e57024ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:23:28 +0100 Subject: [PATCH] call subqueries for cheat sheet --- modules/ROOT/pages/subqueries/call-subquery.adoc | 11 ++++++++++- .../subqueries/subqueries-in-transactions.adoc | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/ROOT/pages/subqueries/call-subquery.adoc b/modules/ROOT/pages/subqueries/call-subquery.adoc index 30dbbb03a..4fba27a0c 100644 --- a/modules/ROOT/pages/subqueries/call-subquery.adoc +++ b/modules/ROOT/pages/subqueries/call-subquery.adoc @@ -50,6 +50,7 @@ The variables returned in a subquery are available to the outer scope of the enc In this example, the `CALL` subquery executes three times, one for each row that the xref:clauses/unwind.adoc[`UNWIND`] clause outputs. .Query +// tag::subqueries_call_subquery_basic_example[] [source, cypher] ---- UNWIND [0, 1, 2] AS x @@ -58,6 +59,8 @@ CALL () { } RETURN innerReturn ---- +// end::subqueries_call_subquery_basic_example[] + .Result [role="queryresult",options="header,footer",cols="m"] @@ -117,6 +120,7 @@ As a result, `CALL` subqueries can help maintain optimal performance and scalabi In this example, a `CALL` subquery is used to xref:functions/aggregating.adoc#functions-collect[`collect`] a `LIST` containing all players who play for a particular team. .Collect a list of all players playing for a particular team +// tag::subqueries_call_subquery_variable_scope[] [source, cypher] ---- MATCH (t:Team) @@ -126,6 +130,8 @@ CALL (t) { } RETURN t AS team, players ---- +// end::subqueries_call_subquery_variable_scope[] + .Result [source, role="queryresult",options="header,footer",cols="m,2m"] @@ -457,6 +463,7 @@ RETURN p.name AS playerName, team.name AS team Note that no results are returned for `Player C`, since they are not connected to any `Team` with a `PLAYS_FOR` relationship. .Query using regular `OPTIONAL CALL` +// tag::subqueries_call_subquery_optional_call[] [source, cypher] ---- MATCH (p:Player) @@ -466,10 +473,10 @@ OPTIONAL CALL (p) { } RETURN p.name AS playerName, team.name AS team ---- +// end::subqueries_call_subquery_optional_call[] Now all `Player` nodes, regardless of whether they have any `PLAYS_FOR` relationships connected to a `Team`, are returned. -.Result .Result [role="queryresult",options="header,footer",cols="2*m"] |=== @@ -572,6 +579,7 @@ Call subqueries can be used to further process the results of a xref:clauses/uni This example query finds the youngest and the oldest `Player` in the graph. .Find the oldest and youngest players +// tag::subqueries_call_subquery_optional_union[] [source, cypher] ---- CALL () { @@ -587,6 +595,7 @@ UNION } RETURN p.name AS playerName, p.age AS age ---- +// end::subqueries_call_subquery_optional_union[] .Result [role="queryresult",options="header,footer",cols="2*