cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How do you return all distinct full paths?

Given the following graph:

I want to get a list of all distinct paths which terminate in the leaf nodes, in string form:

Mobile phone instagram users -> instagram -> facebook -> Company
Mobile phone instagram users -> social network -> Activity
Mobile phone instagram users -> mobile phone -> television and mobile device -> traditional and digital -> Device
Mobile phone instagram users -> mobile phone -> mobile device -> digital -> Device
1 ACCEPTED SOLUTION

You've likely already matched to your starting node. In that case you're looking for variable-length paths of outgoing relationships ending at a leaf node, and the thing that defines a leaf node is that it doesn't have outgoing relationships. So something like this, of course substituting the labels and properties that are actually in your graph

MATCH path = (:Node {name:'Mobile phone instagram users'})-[*]->(leaf)
WHERE NOT (leaf)-->()
RETURN path

View solution in original post

1 REPLY 1

You've likely already matched to your starting node. In that case you're looking for variable-length paths of outgoing relationships ending at a leaf node, and the thing that defines a leaf node is that it doesn't have outgoing relationships. So something like this, of course substituting the labels and properties that are actually in your graph

MATCH path = (:Node {name:'Mobile phone instagram users'})-[*]->(leaf)
WHERE NOT (leaf)-->()
RETURN path