# Collect all unique properties values from my graph using CYPHER

**URL:** <https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [February 26, 2024, 6:09pm UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523 "2024-02-26T18:09:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxime.mock](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/maxime.mock/32/30951_2.png) [@maxime.mock](https://community.neo4j.com/u/maxime.mock)\
**Post date:** [February 26, 2024, 6:09pm UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523/1 "2024-02-26T18:09:44Z")

</div>

Hi !

Firstable I would like to say that I am a beginner in CYPHER queries and KG management.  
I try to find clues on previous topic unsuccesfully, but if I miss something i am sorry.

Secondly : neo4j 5.10.0, Desktp : 1.5.8, Browser 5.12.0

My Goal :  
I would like to make a CYPHER query for getting all my properties values.

Labels | Properties | Values  
Actor | birth\_date | [1957, 1972, ...]  
Actor | name | [Bruce Willis, Natalie Portman,...]  
Film | name | [...]  
...

I succeed to find some but I am not able to aggregate the results for getting my answer.

I am able to :

- Find all the properties as a list

```auto
Match(n)
WITH labels(n) as list_lab_in, keys(n) as Keys
UNWIND Keys as key
WITH DISTINCT collect(key) as list_key
RETURN list_key

```

- Find a table which is close to my need with the query :

```auto
MATCH (n)
WITH n, keys(n) as props
UNWIND props as key
UNWIND labels(n) as Labels
return DISTINCT Labels, Properties, n[key] as Value

```

Output :  
Labels | Properties | Value  
"Label1"| "Property\_1" | "Value"  
"Label1"| "Property\_2" | "Value"  
...

I don't succeed to use a comprehension list for iterate over my list\_key for get all the values of this properties.  
Do I am close to get it ?  
Do anyone have clue to provide ? Any doc, I try APOC doc, CYPHER, but I dont find there.

Kindly,  
Max

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [February 26, 2024, 6:22pm UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523/2 "2024-02-26T18:22:39Z")

</div>

```auto
match (n)
with labels(n) as labels, keys(n) as properties, n
unwind properties as property
return labels, property, n[property] as value limit 10

```

Be ware, this is going to be a long list :)

---

<div class="post-metadata">

**Author:** ![maxime.mock](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/maxime.mock/32/30951_2.png) [@maxime.mock](https://community.neo4j.com/u/maxime.mock)\
**Post date:** [February 27, 2024, 7:56am UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523/3 "2024-02-27T07:56:57Z")

</div>

Hi Hakan,

Firstable thank you about consider my request.

Is it possible to wrap/aggregate all the values under a list ?

I can use this table and get the results i want using python, but I want to improve this query.

The table I get with your answer is very long as you mentionned, the length could be something like count(keys), what i want is a table with a length of count(DISTINCT Keys), with list of all the values possible for the key in the VALUES column.

best regards

---

<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:** [February 27, 2024, 9:46am UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523/4 "2024-02-27T09:46:40Z")

</div>

Try this slight modification to @hakan.lofqvist1’s solution:

```auto
match (n)
with labels(n) as labels, keys(n) as properties, n
unwind properties as property
return labels, property, collect(distinct n[property]) as value
limit 10

```

If you know every node has a single label, you can safely remove the label list in your result:

```auto
match (n)
with head(labels(n)) as label, keys(n) as properties, n
unwind properties as property
return label, property, collect(distinct n[property]) as value
limit 10

```

As a note, null values are ignored in the collect function. If you have some properties with null values, the query can be modified to show this.

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [February 27, 2024, 8:43pm UTC](https://community.neo4j.com/t/collect-all-unique-properties-values-from-my-graph-using-cypher/66523/5 "2024-02-27T20:43:20Z")

</div>

You can also do something like this:

```auto
match (n)
return head(labels(n)) as label, n{.*} as properties
limit 10

```
