# Extract list of Nodes and Labels from path

**URL:** <https://community.neo4j.com/t/extract-list-of-nodes-and-labels-from-path/13665>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [January 15, 2020, 3:43pm UTC](https://community.neo4j.com/t/extract-list-of-nodes-and-labels-from-path/13665 "2020-01-15T15:43:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mdfrenchman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mdfrenchman/32/6094_2.png) [@mdfrenchman](https://community.neo4j.com/u/mdfrenchman)\
**Post date:** [January 16, 2020, 1:32pm UTC](https://community.neo4j.com/t/extract-list-of-nodes-and-labels-from-path/13665/4 "2020-01-16T13:32:09Z")

</div>

Hi @marcos.stival,  
Welcome to the community!

What you're looking for is a way to flatten your list of lists, and then unwind (or pivot them).

```auto
MATCH p = (n:Client)-[r:PARENT_OF*]->(t:Client) 
WHERE n.Code="MYCODE"
// nodes(p) is an array of arrays. the reduce is similar to a flat function.
WITH reduce(output = [], n IN nodes(p) | output + n ) as nodeCollection
// here we take the single row of the flattened array and pivot it to rows.
UNWIND nodeCollection as client
// once we have each client in it's own row, then we call labels 
// Also don't forget the distinct! 
// Remember the arrays simply flatten out each path, 2 of your nodes show up in multiple paths.
RETURN distinct client, labels(client)

```

I hope that was informative while also helping answer the question.  
If you have any other follow on questions, let me know 🙂

-Mike

---

_[View the full topic](https://community.neo4j.com/t/extract-list-of-nodes-and-labels-from-path/13665)._
