# Distinct full paths for a given node

**URL:** <https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528>\
**Category:** Cypher\
**Created:** [October 20, 2020, 10:23am UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528 "2020-10-20T10:23:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico.pelissero](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nico.pelissero/32/8131_2.png) [@nico.pelissero](https://community.neo4j.com/u/nico.pelissero)\
**Post date:** [October 20, 2020, 10:23am UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528/1 "2020-10-20T10:23:03Z")

</div>

Hi everyone,  
For the following graph :  
 ![Capture d’écran du 2020-10-20 10-47-20](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/f/f5b0d1595d480a08bbd7af3335679c42cd57512c.png)

I would like to get all the distinct oriented paths for a given node.  
For example, starting from x6, I would have 3 distinct paths :

- x6 -\> x3 -\> x2 -\> x1

- x6 -\> x3 -\> x2 -\> x4

- x6 -\> x3 -\> x2 -\> x5

I have tried this query: `MATCH path = ({name:'x6'})-[*]->(n) RETURN path`

And I obtained these results:

 ![Capture d’écran du 2020-10-20 12-16-35](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/8/85a94427efccbb19201da7eeeb5bb367414b1fa8.png)

I think I just have to add clauses in my query, but I can't figure out which ones.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [October 20, 2020, 2:13pm UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528/2 "2020-10-20T14:13:34Z")

</div>

> [@nico.pelissero](#):
>
> I would like to get all the distinct oriented paths

What does this mean?

In your sample output, why wouldn't you also want to see x6 -\> x3, x6 -\> x3 -\> x2, and other "intermediate" paths?

---

<div class="post-metadata">

**Author:** ![nico.pelissero](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nico.pelissero/32/8131_2.png) [@nico.pelissero](https://community.neo4j.com/u/nico.pelissero)\
**Post date:** [October 20, 2020, 2:38pm UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528/3 "2020-10-20T14:38:04Z")

</div>

Yes I'm also interested by the "intermediate" paths but is it not possible to simplify by defining that they are included in the next 3 paths ?

- x6 -\> x3 -\> x2 -\> x1
- x6 -\> x3 -\> x2 -\> x4
- x6 -\> x3 -\> x2 -\> x5

I would like to "limit" the research of paths like this:

- First node of the path -\> a given node (x6 for example)
- End node of the path -\> leaf node (like x1 ?) OR a node before the given node (x4 and x5 for x6)

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [October 20, 2020, 2:59pm UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528/4 "2020-10-20T14:59:18Z")

</div>

Have a look at this -- this might be what you mean / need, but I'm not sure

> **[Minimum Weight Spanning Tree - Neo4j Graph Data Science](https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/minimum-weight-spanning-tree/)**
>
> This section describes the Minimum Weight Spanning Tree algorithm in the Neo4j Graph Data Science library.

This would get you all of the paths, as short as possible, from your starting point to everything else, without replications I think.

---

<div class="post-metadata">

**Author:** ![nico.pelissero](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nico.pelissero/32/8131_2.png) [@nico.pelissero](https://community.neo4j.com/u/nico.pelissero)\
**Post date:** [October 21, 2020, 7:36am UTC](https://community.neo4j.com/t/distinct-full-paths-for-a-given-node/27528/5 "2020-10-21T07:36:10Z")

</div>

Thanks David !  
I also think about Shortest Path and Single Source Shortest Path algorithm because I will put cost on my relationship.

I found this code in neo4j documentation :  
[https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/single-source-shortest-path/](https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/single-source-shortest-path/)
