diff --git a/pages/querying/subquery-expressions.mdx b/pages/querying/subquery-expressions.mdx index 229b931b8..7cbeae4bc 100644 --- a/pages/querying/subquery-expressions.mdx +++ b/pages/querying/subquery-expressions.mdx @@ -402,9 +402,8 @@ Output: ### The bare pattern shorthand `EXISTS` and `COUNT` accept a bare pattern in place of a full body, which is a -shorter way to write a check or a count over one pattern. The pattern cannot -introduce names of its own — a variable already bound outside may appear in it, -and acts as a join: +shorter way to write a check or a count over one pattern. A variable already +bound outside may appear in it, and acts as a join: ```cypher MATCH (p:Person) @@ -427,10 +426,32 @@ Output: +---------+-------+---------+ ``` -The shorthand holds a pattern and nothing else, so a filter or any other clause -needs the `MATCH` form — `COUNT { MATCH (p)-[r:KNOWS]->() WHERE r.since < 2015 }`. -`COLLECT` has no shorthand, since a bare pattern returns no column for it to -gather. +The shorthand takes everything a `MATCH` pattern takes: a variable it declares +itself, a trailing `WHERE`, several patterns separated by commas, a named path, +and a pattern holding only a node. + +```cypher +MATCH (p:Person) +RETURN p.name AS name, + COUNT { (p)-[r:KNOWS]->(f:Person) WHERE r.since < 2015 } AS early +ORDER BY name; +``` + +Output: + +```nocopy ++---------+-------+ +| name | early | ++---------+-------+ +| "Alice" | 1 | +| "Bob" | 0 | +| "Carol" | 0 | +| "Dave" | 0 | ++---------+-------+ +``` + +Any other clause still needs the `MATCH` form. `COLLECT` has no shorthand, since +a bare pattern returns no column for it to gather. ### Correlation with the enclosing query