13

I have this kinds of relationships:

(:User)<-[:MENTIONS]-(:Tweet)-[:ABOUT]->(:Topic)

I would like to count all the users mentioned in the tweets regarding some topic.

With the following query

match (n:Topic)<--(t:Tweet)-[:MENTIONS]->(u:User) 
where n.name='politics'
return distinct count(u)

all I get is the relationships count.

What I would like to get is, instead, the number of users mentioned (without duplicates if a user is mentioned several times). How is that possible?

sirdan
  • 1,018
  • 2
  • 13
  • 34

1 Answers1

20

Try putting distinct inside count function, this way:

match (n:Topic)<-[:ABOUT]-(t:Tweet)-[:MENTIONS]->(u:User) 
where n.name='politics'
return count(distinct u)
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • 1
    @sirdan You are welcome! If this answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Bruno Peres Nov 29 '17 at 10:41
  • 1
    Of course I accept it, I was waiting some minutes because the system didn't allow me to accept it before 10 minutes. – sirdan Nov 29 '17 at 10:42