I have
MATCH (x)-[rels*]->(y)
RETURN extract( r in rels | r.property) as collected
where collected
is a collection of properties of all relationships along the path, such as [null, 4, null, 4]
or [1, 3, 3, 1]
.
How can I further extract from collected
only its unique values?
For example, [null, 4, null, 4]
would change into [null, 4]
UNWIND expands a list into a sequence of rows.
The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.
The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.
try this instead:
MATCH (x)-[rels*]->(y)
UNWIND rels AS rel
RETURN COLLECT( distinct rel.property) AS collected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With