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

**URL:** <https://community.neo4j.com/t/how-to-match-nodes-with-different-labels-that-have-any-relationship/12727>\
**Category:** Newbie Questions\
**Created:** [December 10, 2019, 7:42pm UTC](https://community.neo4j.com/t/how-to-match-nodes-with-different-labels-that-have-any-relationship/12727 "2019-12-10T19:42:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laoikeda](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/laoikeda/32/7409_2.png) [@laoikeda](https://community.neo4j.com/u/laoikeda)\
**Post date:** [December 10, 2019, 7:42pm UTC](https://community.neo4j.com/t/how-to-match-nodes-with-different-labels-that-have-any-relationship/12727/1 "2019-12-10T19:42:33Z")

</div>

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:

![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/e/ea115fae9da4eff2554b918d699fe7b1c6f46171.png)

---

<div class="post-metadata">

**Author:** ![shan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shan/32/7767_2.png) [@shan](https://community.neo4j.com/u/shan)\
**Post date:** [December 10, 2019, 7:50pm UTC](https://community.neo4j.com/t/how-to-match-nodes-with-different-labels-that-have-any-relationship/12727/2 "2019-12-10T19:50:28Z")

</div>

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:

```auto
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

```
