'Returning cousins in Neo4j problem with WHERE

I have to make a Cypher query which is supposed to return cousins of a person (brothers, sisters, kids of brothers/sisters). It works almost fine, but the problem is that when I want to filter out the kids of the person (27003) (precious) writing WHERE p2.personId<>27003 it also removes the mother of the person (missing).

What have I done wrong here?

My cypher query:

MATCH (p: Person_kol)<-[]-(parent: Person_kol) WHERE p.idPerson=27003
WITH p,parent
MATCH (p3: Person_kol)<-[]-(p2: Person_kol)<-[]-(parent: Person_kol)
WHERE p2.idPerson<>27003
RETURN p,parent,p3,p2

My first match just returns the person of given id with his/her parent.

Second match just searches for brothers/sisters and his/her kids (I know that p2 also includes the person of id=27003 and his/her kids, that's why I want to filter them out, but my "WHERE" also removes the mother of the person (2nd picture)

Pictures:

  1. (without WHERE clause)

text

  1. (with WHERE)

text



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source