# How to match a path, by stop by a condition

**URL:** <https://community.neo4j.com/t/how-to-match-a-path-by-stop-by-a-condition/27409>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [October 18, 2020, 3:48pm UTC](https://community.neo4j.com/t/how-to-match-a-path-by-stop-by-a-condition/27409 "2020-10-18T15:48:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninesunqian](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ninesunqian/32/4239_2.png) [@ninesunqian](https://community.neo4j.com/u/ninesunqian)\
**Post date:** [October 18, 2020, 3:48pm UTC](https://community.neo4j.com/t/how-to-match-a-path-by-stop-by-a-condition/27409/1 "2020-10-18T15:48:03Z")

</div>

Hello!  
I have a graph: root(neo4j id : 0) -[:include]-\> childA(neo4j id 1) -[:include]-\> childAA(neo4j id 2) -[:include]-\> childAAA(neo4j id 3)  
I want match from childAAA reversely along include edge, but stop when the endNode of current edge in node set [0, 1]. In other words root-\>childA is not in result, but childA-\>childAA should be in.

I don't know how to write the cypher statement. I'm looking forward to help!  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [October 18, 2020, 5:21pm UTC](https://community.neo4j.com/t/how-to-match-a-path-by-stop-by-a-condition/27409/2 "2020-10-18T17:21:26Z")

</div>

```auto
You can start from childA(neo4j id 1).

//insert correct node info.....
MATCH childA(neo4j id 1)
CALL apoc.path.subgraphNodes(a, {relationshipFilter:'include>'}) 
YIELD node
RETURN node

This should give you the desired result.
 

```

---

<div class="post-metadata">

**Author:** ![ninesunqian](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ninesunqian/32/4239_2.png) [@ninesunqian](https://community.neo4j.com/u/ninesunqian)\
**Post date:** [October 19, 2020, 3:50pm UTC](https://community.neo4j.com/t/how-to-match-a-path-by-stop-by-a-condition/27409/3 "2020-10-19T15:50:46Z")

</div>

Thank you! I get the method also:  
match p = (n)\<-[r:include\*..]-() where id(n)=3 AND not id(nodes(p)[-1]) in [0, 1] return p
