cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Why is WITH statement not required here?

I am currently doing this Cypher Graph Modelling Course Adding a Role Node | GraphAcademy (neo4j.com)
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.

1 REPLY 1

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.