Q:

Searching not exists in Neo4j via Cypher

I have some relations between persons in my graph.
my data (generate script below)
create (s:Person {name: "SUE"}) 
create(d:Person {name: "DAVID"}) 
create(j:Person {name: "JACK"}) 
create(m:Person {name: "MARY"}) 
create(js:Person {name: "JASON"}) 
create(b:Person {name: "BOB"}) 
create(a1:Adress {id:1}) 
create(a2:Adress {id:2}) 
create(a3:Adress {id:3}) 
create(a4:Adress {id:4}) 
create(a5:Adress {id:5}) 
merge (d)-[:MOTHER]->(s) 
merge(j)-[:MOTHER]->(s) 
merge(js)-[:MOTHER]->(m) 
merge(b)-[:MOTHER]->(m) 
merge(b)-[:CURRENT_ADRESS]->(a1) 
merge(js)-[:CURRENT_ADRESS]->(a2) 
merge(j)-[:CURRENT_ADRESS]->(a3) 
merge(s)-[:CURRENT_ADRESS]->(a4) 
merge(d)-[:CURRENT_ADRESS]->(a5)

;
I can get mothers who live with her child:
MATCH (p:Person)-[:CURRENT_ADRESS]->(a:Adress)<-[:CURRENT_ADRESS]-(t), (t)-[:MOTHER]->(p)
return p.name,t.name

p.name  t.name
MARY    JASON

but i want to get mothers who is not living with any child of her.
How can i do that in Cyper?

A:

Actually in your graph, everybody is living at a different address due to different identifiers.
Let's build a graph example introducing the sister which lives at the same address :
CREATE 
(p:Person)-[:MOTHER]->(m:Person),
(p)-[:FATHER]->(f:Person),
(p)-[:SISTER]->(s:Person),
(p)-[:CURRENT_ADDRESS]->(a:Adress),
(m)-[:CURRENT_ADDRESS]->(b:Adress),
(f)-[:CURRENT_ADDRESS]->(c:Adress),
(s)-[:CURRENT_ADDRESS]->(a)

Now this is very simple, match family members that don't have a CURRENT_ADDRESS relationship in depth2 to the family member :
MATCH (p:Person)-[:MOTHER|:FATHER|:SISTER]->(familyMember)
WHERE NOT EXISTS((p)-[:CURRENT_ADDRESS*2]-(familyMember))
RETURN familyMember

