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.

How to match nodes with different labels that have any relationship?

laoikeda
Node Link

Basicaly, I want to match nodes that have some kind of relationship, but only when the nodes in this relationship do not have the same label.
I'll use that to match duplicate relationships on different node labels.
In the end I want to be able to get this kind of subgraph:

2X_e_ea115fae9da4eff2554b918d699fe7b1c6f46171.png

1 REPLY 1

shan
Graph Buddy

A node can have multiple labels. If you don't want any common label between the two ends of an edge, you can use something like this:

MATCH (a)-[r]->(b) 
WHERE ALL(x IN labels(a) WHERE NOT x IN labels(b)) AND ALL(x IN labels(b) WHERE NOT x IN labels(a))
RETURN a, r, b