Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-15-2022 08:06 AM - last edited on 07-25-2022 09:16 AM by TrevorS
Hello community,
I am new to neo4j and I'm trying to get a list of nodes (that has not a specific relation) and count node name duplicates.
Query:
MATCH (e:ExampleNode) WHERE NOT exists((e)-[:EXAMPLE_REL]->()) RETURN e.name as name, count(e.name) as count
Result:
name1 | 3 |
name23 | 1 |
name8 | 4 |
So far so good...
Beside the name of the node I also need some more values. This value makes each result unique and returns every node separately even (if the name is the same).
Query:
MATCH (e:ExampleNode) WHERE NOT exists((e)-[:EXAMPLE_REL]->()) RETURN e.name as name, count(e.name) as count, e.property as someValue
Result:
name1 | 1 | abc |
name1 | 1 | cba |
name1 | 1 | xyz |
name23 | 1 | abc |
name8 | 1 | 123 |
name8 | 1 | 321 |
name8 | 1 | 987 |
name8 | 1 | 789 |
... | ... | ... |
But...this is the result I would like to have:
name1 | 3 | abc |
name1 | 3 | cba |
name1 | 3 | xyz |
name23 | 1 | abc |
name8 | 4 | 123 |
name8 | 4 | 321 |
name8 | 4 | 987 |
name8 | 4 | 789 |
... | ... | ... |
I would like to return every node that hasn't the specific relation and count all duplicates by the name.
So, is it possible to get the result I would like to have?
Solved! Go to Solution.
06-15-2022 08:40 AM
Hello @ovashape 🙂
MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
WITH e.name as name, count(e.name) AS count, collect(e.property) AS values
UNWIND values AS value
RETURN name, count, value
Regards,
Cobra
06-15-2022 08:40 AM
Hello @ovashape 🙂
MATCH (e:ExampleNode)
WHERE NOT exists((e)-[:EXAMPLE_REL]->())
WITH e.name as name, count(e.name) AS count, collect(e.property) AS values
UNWIND values AS value
RETURN name, count, value
Regards,
Cobra
06-15-2022 08:46 AM
Thanks for your quick answer. This solved my problem.
All the sessions of the conference are now available online