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.

Finding Nodes that do not have a relationship

gq16
Node Clone

I don't know why this seems so difficult to figure out. I'm working with the following Nodes and relationships:
3X_5_2_52e1b60260c00cc5a75523d8ee835d8aa4192961.png

I have this code:
MATCH

(n:Notification)-[cfn:CONTACT_FIRST_NAME]->(fn:Name)<-[hfn:HAS_FIRST_NAME]-(c:Contact),

(n)-[cln:CONTACT_LAST_NAME]->(ln:Name)<-[hln:HAS_LAST_NAME]-(c)

RETURN *

And it gives me the first and last names of those who have received a notification and are also a "Contact", but I want to find the names that received a notification, but are not a name owned by a "Contact"

I tried using the WHERE NOT clause, but it didn't yield the proper results. Please help me!

1 ACCEPTED SOLUTION

Hi @gq16

How about this?

I created two person data.

CREATE (n:Notification {id: 1})-[:CONTACT_FIRST_NAME]->(:Name {name:"Gehad"})<-[:HAS_FIRST_NAME]-(c:Contact),
(n)-[:CONTACT_LAST_NAME]->(:Name {name:"Qaki"})<-[:HAS_LAST_NAME]-(c);
CREATE (n:Notification {id: 2})-[:CONTACT_FIRST_NAME]->(:Name {name:"Koji"}),
(n)-[:CONTACT_LAST_NAME]->(:Name {name:"Annoura"});

The query is like this.

MATCH
(n:Notification)-[cfn:CONTACT_FIRST_NAME]->(fn:Name),
(n)-[cln:CONTACT_LAST_NAME]->(ln:Name)
WHERE NOT (fn)<-[:HAS_FIRST_NAME]-(:Contact)-[:HAS_LAST_NAME]->(ln)
RETURN *

View solution in original post

2 REPLIES 2

Hi @gq16

How about this?

I created two person data.

CREATE (n:Notification {id: 1})-[:CONTACT_FIRST_NAME]->(:Name {name:"Gehad"})<-[:HAS_FIRST_NAME]-(c:Contact),
(n)-[:CONTACT_LAST_NAME]->(:Name {name:"Qaki"})<-[:HAS_LAST_NAME]-(c);
CREATE (n:Notification {id: 2})-[:CONTACT_FIRST_NAME]->(:Name {name:"Koji"}),
(n)-[:CONTACT_LAST_NAME]->(:Name {name:"Annoura"});

The query is like this.

MATCH
(n:Notification)-[cfn:CONTACT_FIRST_NAME]->(fn:Name),
(n)-[cln:CONTACT_LAST_NAME]->(ln:Name)
WHERE NOT (fn)<-[:HAS_FIRST_NAME]-(:Contact)-[:HAS_LAST_NAME]->(ln)
RETURN *

Incredible! Thank you for your help Koji!