Showing results for 
Search instead for 
Did you mean: 

Why is WITH statement not required here?

I am currently doing this Cypher Graph Modelling Course Adding a Role Node | GraphAcademy (
I was wondering why don't we need the with keyword in the example shown?


// Find an actor that acted in a Movie
MATCH (a:Actor)-[r:ACTED_IN]->(m:Movie)

// Create a Role node
MERGE (x:Role {name: r.role})

// Create the PLAYED relationship
// relationship between the Actor and the Role nodes.
MERGE (a)-[:PLAYED]->(x)

// Create the IN_MOVIE relationship between
// the Role and the Movie nodes.
MERGE (x)-[:IN_MOVIE]->(m)


 I thought it should look something like:
WITH r.role as role
MERGE (x:Role {name: role})

Why is it that the variables: a, r, m, x are available in the later clauses without using the WITH keyword?
I remember in other examples in the tutorial, the WITH keyword was used.



Because you can have a string of merges follow a string of matches. 

you will need a with if you go from a merge to a new string of matches. 

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.