Working with the WITH clause
In Cypher, the WITH
clause allows individual queries to be chained together by streaming the results from the first part of the query to the next part of the query. It allows you to manipulate the query result before it is passed on to the next part of the query.
We will take a look at different ways in which we can work with the WITH
clause. We will start by introducing the variables at the beginning of the Cypher query.
Introducing variables at the start
When a query starts with the WITH
clause, we need to introduce the variables for the next part of the query.
Let’s look at an example:
WITH range(1,5,1) as list RETURN list
In this query, we are introducing a variable called list
and returning it.
The following screenshot shows how to prepare a new variable using the WITH
clause and return values based on that variable.
Figure 8.1 – Basic WITH usage introducing a new variable at the start
Now...