# How many times each node collaborated with other nodes

**URL:** <https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817>\
**Category:** Cypher\
**Created:** [November 6, 2018, 4:59pm UTC](https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817 "2018-11-06T16:59:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehdi.ajroud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mehdi.ajroud/32/1045_2.png) [@mehdi.ajroud](https://community.neo4j.com/u/mehdi.ajroud)\
**Post date:** [November 6, 2018, 4:59pm UTC](https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817/1 "2018-11-06T16:59:20Z")

</div>

All what I need is knowing how many times each node collaborated with other nodes , I found [this example](https://community.neo4j.com/t/count-relationship-on-each-nodes/1566) and I followed it .  
I runned this query :

```auto
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->(m)) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators

```

But I am getting the same value for all "NumberOfRelations" which is "1" .  
Anyone has a solution and could help please ?

---

<div class="post-metadata">

**Author:** ![mckenzma](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mckenzma/32/78_2.png) [@mckenzma](https://community.neo4j.com/u/mckenzma)\
**Post date:** [November 6, 2018, 6:07pm UTC](https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817/2 "2018-11-06T18:07:36Z")

</div>

Based on the example you reference your issue my be with `size((n)-->(m))`.

In the example, @Benoit uses `size((n)-->())`. In this example leaving the second node "emtpy" `()` lets you count all of those that are connected. However, in your example, using `(m)` means you are only counting the relationships between `(m)` and `(n)`. Unless you have multiple relationships connecting these nodes, you will always get "1".

Try using

```auto
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->()) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators

```

---

<div class="post-metadata">

**Author:** ![bratanic\_tomaz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bratanic_tomaz/32/26823_2.png) [@bratanic\_tomaz](https://community.neo4j.com/u/bratanic_tomaz)\
**Post date:** [November 6, 2018, 7:41pm UTC](https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817/3 "2018-11-06T19:41:35Z")

</div>

I think you can simplify you query:

```auto
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
WITH n.id as Attributaires , m.id AS Collaborators, count(*) AS NumberOfRelations 
RETURN Attributaires , NumberOfRelations , Collaborators

```

---

<div class="post-metadata">

**Author:** ![mehdi.ajroud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mehdi.ajroud/32/1045_2.png) [@mehdi.ajroud](https://community.neo4j.com/u/mehdi.ajroud)\
**Post date:** [November 7, 2018, 3:20pm UTC](https://community.neo4j.com/t/how-many-times-each-node-collaborated-with-other-nodes/2817/4 "2018-11-07T15:20:24Z")

</div>

This query give me the same results . But @mckenzma query worked :)
