Swaroop
Swaroop

Reputation: 541

Getting Unmatched Result Values in Neo4J

I am trying to execute a cypher query to Match a result set for a case where a "User" "Writes" a "Post" and also match if any "Reply" has been received for the respective "Post" with a relation name as "ReplyOf". Following is the query that I have tried.

match (user1:User)-[:WRITES]->(p:Post)
optional match (r:Reply)-[:REPLYOF]->(p)
where user1.Email="[email protected]"
return p,r

My Problem is that instead of returning only the particular Post and Reply(if any available) as per the condition provided in the where clause, I am getting the entire Posts results of all users. What could be the reason for such occurence? One thing I have noted is that, if I exclude the optional match statement from query then it provides the correct matched post as per the where condition. Please suggest what could be wrong with query.

Upvotes: 0

Views: 378

Answers (1)

TheTeacher
TheTeacher

Reputation: 510

move the where clause to before optional match

Upvotes: 1

Related Questions