cancel
Showing results for 
Search instead for 
Did you mean: 

How to return all end nodes of a tree?

marcelix161
Node Clone

What is the best way to get all the end nodes of a tree? Can it be achieved with a pure cypher or apoc function?
I've thought that I can return all of them based on the fact they don't have any outcoming relationships. Would it be possible?

1 ACCEPTED SOLUTION

bennu_neo
Neo4j
Neo4j

Hi @marcelix161 ,

You can execute a pure cypher query like

MATCH(:root {//root condition})-[:MINST*]->(leaf)
where not (leaf)-[:MINST]->()
return leaf

Bennu

Oh, y’all wanted a twist, ey?

View solution in original post

1 REPLY 1

bennu_neo
Neo4j
Neo4j

Hi @marcelix161 ,

You can execute a pure cypher query like

MATCH(:root {//root condition})-[:MINST*]->(leaf)
where not (leaf)-[:MINST]->()
return leaf

Bennu

Oh, y’all wanted a twist, ey?
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.