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.

Filtering for the same condition of repeated relationships

Hi Everyone,

I'm trying to filter my Cypher query to keep paths where a repeated relationship has a certain value.
I would like to do something like:-

MATCH p= (c1:Company)-[r:Phoe_Of*1..3]->(c:Company)
where c.date_dissolved is null and c1.date_dissolved is null and r.susp = '1' 
RETURN p

But am having to do something like the code below as i can't reuse the same aliases:-

MATCH p= (c1:Company)-[r:Phoe_f]-()-[r1:Phoe_Of]-()-[r2:Phoe_Of]->(c:Company)
where c.date_dissolved is null and c1.date_dissolved is null and r.susp = '1' and r1.susp = '1' and r2.susp = '1'
RETURN p

Is there a simple, more efficient way to do this?

Many thanks,

Sam

1 ACCEPTED SOLUTION

there is: r is an array variable in your case so apply the all predicate:

where c.date_dissolved is null and c1.date_dissolved is null 
and all(x in r where x.susp=1)
RETURN p```

View solution in original post

2 REPLIES 2

there is: r is an array variable in your case so apply the all predicate:

where c.date_dissolved is null and c1.date_dissolved is null 
and all(x in r where x.susp=1)
RETURN p```

Excellent, thanks Stefan.