Count 2 relationships in a single cypher query

match (a:User {name: "HakumanaTata"}) ,(a)<-[f:Follows]-(:User) ,(a)-[F:Follows]->(:User) return count(f) as Followers, count(F) as Following

This returns nothing.
Also, which is faster, counting relationships or counting nodes?


match (a:User {name: "HakumanaTata"}) return a;

report any data? if not then no such :User node exists.

if you run

match (a:User {name: "HakumanaTata"}) 
return size   (  (a)-[:Follows]->()  ) as Followers,
            size   (  (a)<-[:Follows]-()   )  as Following

should be fast and do what I suspect what you might be after however this is dependent on the fact that the :Follows relationship only connects to :User nodes.

See Fast counts using the count store - Knowledge Base for more details

1 Like

Thank you very much.. I don't know why the previous query did not execute correctly... the user I searched for definitely exists., fortunately for me your solution worked.