cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to count distinct couples

Hello, I have this query

match (c1:CI)-[:USES]->(c2:CI)
return distinct c1.name,c2.name

Now I would like to count the rows, but I don't seem to be able to figure this out!

I tried

return count(*)

but this does count duplicates.

I tried

return count (distinct c1.name)

but this is wrong, as it counts only the "users", not the distinct relationships.

Other attempts gave me error.

Could you help?

Tnx!

1 ACCEPTED SOLUTION

Hello @dario.piantanida and welcome to the Neo4j community

MATCH (c1:CI)-[:USES]->(c2:CI)
WITH DISTINCT c1.name AS c1_name, c2.name AS c2_name
RETURN count(c1_name) AS couples

Regards,
Cobra

View solution in original post

1 REPLY 1

Hello @dario.piantanida and welcome to the Neo4j community

MATCH (c1:CI)-[:USES]->(c2:CI)
WITH DISTINCT c1.name AS c1_name, c2.name AS c2_name
RETURN count(c1_name) AS couples

Regards,
Cobra