# How to query multiple relationships in Cypher

**URL:** https://community.neo4j.com/t/how-to-query-multiple-relationships-in-cypher/53443
**Category:** Cypher
**Tags:** cypher
**Created:** [March 15, 2022, 9:14pm UTC](https://community.neo4j.com/t/how-to-query-multiple-relationships-in-cypher/53443 "2022-03-15T21:14:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![heena.rajan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/heena.rajan/32/22965_2.png) [@heena.rajan](https://community.neo4j.com/u/heena.rajan)
#### Post date: [March 15, 2022, 9:14pm UTC](https://community.neo4j.com/t/how-to-query-multiple-relationships-in-cypher/53443/1 "2022-03-15T21:14:14Z")

</div>

Hello Everyone,  
I am new to Cypher and having issues while querying for multiple relationships. I have two relationships :abc and :xyz. I want to get all the nodes that are 2 hops away which have either :abc OR :xyz relationships. Also, :abc is directional, whereas :xyz is bidirectional.  
I tried

```auto
MATCH(n)-[:abc*1..2]->(m),
(m)-[:xyz*1..2]-(o)
RETURN n, m, o

```

But, it gives the result with AND condition and hence the nodes which do not have :xyz relations are not included. How can I solve it?  
Thanks in advance.

---

<div class="post-metadata">

### Author: ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)
#### Post date: [March 15, 2022, 10:51pm UTC](https://community.neo4j.com/t/how-to-query-multiple-relationships-in-cypher/53443/2 "2022-03-15T22:51:01Z")

</div>

You can use the following pattern to query for relationships that have one of several relationships;

()-[:X|Y|Z]-()

Using match (n)-[:abc|xyz]-() would not work in your case because you could get paths with the wrong direction for the 'abc' relationship type.

If your requirement is paths of length 2 that consist of relationships with type either 'abc' or 'xyz', then the only combinations are the following permutations:

()-[:abc]-\>()-[:abc]-\>()  
()-[:xyz]-()-[:xyz]-()  
()-[:abc]-\>()-[:xyz]-()  
()-[:xyz]-()-[:abc]-\>()

I think the following query will provide this. I am assuming the direction of the 'abc' relationships are the same.

MATCH p=()-[:abc_0..1]-\>()-[:xyz_0..2]-()-[:abc\*0..1]-\>()  
WHERE length(p) = 2  
RETURN nodes(p) as nodes

Sorry I don't have any data to fully test it.
