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.

Unable to match two nodes with where (Syntax error)

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

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

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.