cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to match two nodes with where (Syntax error)

fruitfulapproac
Graph Buddy
MATCH (n:Object)
MATCH (m:Object)
WHERE n.name = "A"
WHERE m.name = "B"
RETURN n,m

In the browser, complains of a syntax error: Unexpected "H" at line 4 column 2

1 ACCEPTED SOLUTION

tard_gabriel
Ninja
Ninja

MATCH (n:Object) WHERE n.name = "A"
MATCH (m:Object) WHERE m.name = "B"
RETURN n,m

OR

MATCH (n:Object {name: "A"})
MATCH (m:Object {name: "B"})
RETURN n,m

OR

MATCH (n:Object {name: "A"}), (m:Object {name: "B"})
RETURN n,m

OR

MATCH (o:Object) WHERE o.name IN ["A","B"]
RETURN o

WHERE is not a clause but a subclause, it must follow directly its associated match or optional match. In your case WHERE n.name = "A" doesn't follow directly its MATCH (n:Object) clause.

View solution in original post

1 REPLY 1

tard_gabriel
Ninja
Ninja

MATCH (n:Object) WHERE n.name = "A"
MATCH (m:Object) WHERE m.name = "B"
RETURN n,m

OR

MATCH (n:Object {name: "A"})
MATCH (m:Object {name: "B"})
RETURN n,m

OR

MATCH (n:Object {name: "A"}), (m:Object {name: "B"})
RETURN n,m

OR

MATCH (o:Object) WHERE o.name IN ["A","B"]
RETURN o

WHERE is not a clause but a subclause, it must follow directly its associated match or optional match. In your case WHERE n.name = "A" doesn't follow directly its MATCH (n:Object) clause.