NEO4j Cypher query returning distinct value
19,719
Distinct works on the whole row, if you want to return distinct friends per company, do:
return comp.name, collect(distinct friend.name)
Author by
Hussain
Updated on June 05, 2022Comments
-
Hussain almost 2 years
hello guys I am new to cypher query and I want to restrict duplicate values in my result
the query is
match (ee:Personal {id:"id"})-[:Friend]->(fr), (fr)-[:Friend]->(fr2), (fr2)-[:Friend]->(friend:Personal), (friend)-[:Works]->(comp:Company) where comp.name=~".*name.*" and not friend.id="id" and not (friend)-[:Friend]-(fr) and not (friend)-[:Friend]-(ee) and not (fr2)-[:Friend]-(ee) optional match (comp)-[:Position]->(pos), (friend)-[:Position]->(pos) optional match (friend)-[:Location]->(loc) return distinct friend.name, comp.name
but i get duplicate values as there are multiple node properties in return statemnt. If I return only one property then its fine. but i want distinct friends