Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

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

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:



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