# How to query the node and its any downstream node's property

**URL:** https://community.neo4j.com/t/how-to-query-the-node-and-its-any-downstream-nodes-property/61466
**Category:** Cypher
**Tags:** cypher, property, downstream
**Created:** [March 16, 2023, 9:18am UTC](https://community.neo4j.com/t/how-to-query-the-node-and-its-any-downstream-nodes-property/61466 "2023-03-16T09:18:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Peter\_Lian](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@Peter\_Lian](https://community.neo4j.com/u/Peter_Lian)
#### Post date: [March 16, 2023, 9:18am UTC](https://community.neo4j.com/t/how-to-query-the-node-and-its-any-downstream-nodes-property/61466/1 "2023-03-16T09:18:21Z")

</div>

There is only one type of node which name " **User**" (in green) and one type of edge which name " **sell\_product\_to**" (in green) in my database, i.e., the following

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/d/4dc904564a75cc2c001a0b66ffd16b6d91f8f9d5.png)

There're five group (or user-chain) in above figure where the name that behind each node is the node's property ( **username** ).

Question : I want to query the node which the name is **Lin** in any **Peter's downstream node** and return the entire group (user-chain), i.e., the following result

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/2/123d0bf80565e4bd1e10fc5264b46ffa211f420a.png)

I tried the following cypher:

`Match(n:User)-[r:sell_product_to]->(p:User) where n.username ='Peter' AND p.username='Lin' RETURN n,r,p`

The result is the following :

![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/c/7/c72edb6b41ac1d0f14e8adf84dad957d6293ae59.png)

Obviously it fail since not only the Henry node do not return but also lack other two user-chains where Peter's next user is not Lin but in Peter's downstream.

So, how can I make it? or **at least** return the node and edge between Peter and Lin but the entire chain don't show, i.e., the following

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/a/f/af2c460024f85f084e06abd4b374b267f7c84f01.png)

Thanks.

---

<div class="post-metadata">

### Author: ![lyonwj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lyonwj/32/27358_2.png) [@lyonwj](https://community.neo4j.com/u/lyonwj)
#### Post date: [March 16, 2023, 6:06pm UTC](https://community.neo4j.com/t/how-to-query-the-node-and-its-any-downstream-nodes-property/61466/2 "2023-03-16T18:06:33Z")

</div>

Try using the [variable length path operator (`*`)](https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength) to find arbitrary length paths connect Peter and Lin. Something like:

```auto
MATCH userPath=(n:User)-[r:sell_product_to*]->(p:User) 
where n.username ='Peter' AND p.username='Lin'
RETURN userPath

```

---

<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 17, 2023, 12:11pm UTC](https://community.neo4j.com/t/how-to-query-the-node-and-its-any-downstream-nodes-property/61466/3 "2023-03-17T12:11:06Z")

</div>

Combining @lyonwj's suggestion to get graphs that contain paths between Peter and Lin, then using an APOC path method to get the subgraph originating from the each 'Peter' node.

```auto
Match (n:User{username:'Peter'})-[:sell_product_to*]->(:User{username:'Lin'})
with n
CALL apoc.path.subgraphAll(n, {})
YIELD nodes, relationships
RETURN nodes, relationships

```
