16.16. With

16.16.1. Filter on aggregate function results
16.16.2. Alternative syntax of with

The ability to chain queries together allows for powerful constructs. In Cypher, the WITH clause is used to pipe the result from one query to the next.

WITH is also used to separate reading from updating of the graph. Every sub-query of a query must either be a read-only or a write-only.

Graph

cypher-with-graph.svg

16.16.1. Filter on aggregate function results

Aggregated results have to pass through a WITH clause to be able to filter on.

Query

START david=node(1)
MATCH david--otherPerson-->()
WITH otherPerson, count(*) as foaf
WHERE foaf > 1
RETURN otherPerson

The person connected to David with the at least more than one outgoing relationship.

Result

otherPerson
1 row
0 ms

Node[3]{name->"Anders"}


16.16.2. Alternative syntax of with

If you prefer a more visual way of writing your query, you can use equal-signs as delimiters before and after the column list. Use at least three before the column list, and at least after.

Query

START david=node(1)
MATCH david--otherPerson-->()
========== otherPerson, count(*) as foaf ==========
SET otherPerson.connection_count = foaf

The person connected to David with the at least more than one outgoing relationship.

Result

Properties set: 2
2 ms

(empty result)