Assuming the nodes are successfully retrieved, how many relationships are created?
MATCH (a:Person), (m:Movie)
WHERE a.name = 'Tom Jones' AND m.title = 'Life is Wonderful'
CREATE (a)-[rel:ACTED_IN]->(m)
CREATE (a)-[rel:ACTED_IN {roles: ['The Villain']}]->(m)
CREATE (a)-[rel:ACTED_IN {roles: ['The Villain','Joe']}]->(m)
The right answer is 3. But when I ran the code I got error: Variable rel already declared (line 4, column 13 (offset: 132))
"CREATE (a)-[rel:ACTED_IN {roles: ['The Villain']}]->(m)"
So basically this code creates 0 relationships, not 3. Correct?
If All the relationships are specified and is already retrieved then nothing needs to be created but this is conditional. If something is removed/deleted or detached then the entity that is removed/deleted/detached needs to be reattached or (created again and attached).
is implicitly trying to create a new variable rel (as a ACTED_IN relationship type) when rel was already created in the previous CREATE statement. This is an error!
Since the variable rel is never referred to again in the query, the proper Cypher code for this question is:
MATCH (a:Person), (m:Movie)
WHERE a.name = 'Tom Jones' AND m.title = 'Life is Wonderful'
CREATE (a)-[:ACTED_IN]->(m) // you could use rel one time here: CREATE (a)-[rel:ACTED_IN]->(m)
CREATE (a)-[:ACTED_IN {roles: ['The Villain']}]->(m) // Don't use rel again!
CREATE (a)-[:ACTED_IN {roles: ['The Villain','Joe']}]->(m)
In which case, the answer of 3 is correct.
So, this is an error in the question. Do you have the URL?
(And good for you, for actually trying to query!)
[added]
This is another possibility is to use three different rel variables (which could be used later elsewhere but aren't in this query):
MATCH (a:Person), (m:Movie)
WHERE a.name = 'Tom Jones' AND m.title = 'Life is Wonderful'
CREATE (a)-[rel1:ACTED_IN]->(m)
CREATE (a)-[rel2:ACTED_IN {roles: ['The Villain']}]->(m)
CREATE (a)-[rel3:ACTED_IN {roles: ['The Villain','Joe']}]->(m)