cancel
Showing results for 
Search instead for 
Did you mean: 

EXIT with constraints

depire
Node Clone

Dear all,

I am looking for how to introduce constraints in EXIST clause.

If you consider relationship called REL with one property (share), I am looking for nodes such they have no parents via REL .

I woulk-d like something like
MATCH (n:NODE) WHERE NOT EXISTS( ()-[r:REL]->(n) WHERE r.share > 50.0) RETURN n

How can I rewrite this code to be runnable ?

Thnaks.
Alexandre

2 REPLIES 2

Cobra
Ninja
Ninja

Hello @depire

OPTIONAL MATCH ()-[r:REL]->(n:NODE)
WHERE NOT EXISTS(()-[r]->(n))
OR r.share > 50.0
RETURN n

Regards,
Cobra

depire
Node Clone

Unfortunately, this solution doesn't work, because the second clause must in the first clause.

2X_b_bc1ffe371a828a38f757fab96ef5ce0017685caa.png

To illustrate, I give the data.
CREATE (:LEU{LEID:"A"})
CREATE (:LEU{LEID:"B"})
CREATE (:LEU{LEID:"C"})
CREATE (:LEU{LEID:"D"})
CREATE (:LEU{LEID:"E"})
CREATE (:LEU{LEID:"F"})
CREATE (:LEU{LEID:"G"})
CREATE (:LEU{LEID:"H"})

MATCH (a:LEU{LEID:"A"})
MATCH (b:LEU{LEID:"B"})
CREATE (a)-[r:REL]->(b) SET r.share = 100.0, r.type=1
MATCH (b:LEU{LEID:"B"})
MATCH (a:LEU{LEID:"A"})
CREATE (b)-[r:REL]->(a) SET r.share = 10.0, r.type=1
MATCH (c:LEU{LEID:"C"})
MATCH (e:LEU{LEID:"E"})
CREATE (c)-[r:REL]->(e) SET r.share = 100.0, r.type=1
MATCH (d:LEU{LEID:"D"})
MATCH (e:LEU{LEID:"E"})
CREATE (d)-[r:REL]->(e) SET r.share = 100.0, r.type=2
MATCH (f:LEU{LEID:"F"})
MATCH (g:LEU{LEID:"G"})
CREATE (f)-[r:REL]->(g) SET r.share = 10.0, r.type=1
MATCH (g:LEU{LEID:"G"})
MATCH (h:LEU{LEID:"H"})
CREATE (g)-[r:REL]->(h) SET r.share = 100.0, r.type=1

After running wcc algorithm with r.share > 50.0, we have the following clusters:
0: A, B
1: C,D,E
2: G,H
3: F

My goal is to find the clusters with only one parent and returns the parent.
So I would like to retrieve something like:
Cluster Parent
0 A (because the relationship having B as parent is below 50.0)
2 G because F is not in the same cluster, because the share is below 50.0
3 F

Maybe it is more clear now.

Do you find the solution ?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.