Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-26-2020 09:44 AM
I would like to count how many (User)
nodes exists for a which there is a direct relationship with a (Keyword)
node.
If I do
Match (u:User)-[]->(k:Keyword) Return Count(u)
then the same user may be counted multiple times since it can have connections to different keywords. How do I account for this?
06-26-2020 10:41 AM
Assuming the Keyword node has a property 'name' with values: name: 'cat', name: 'dog'
Match (u:User)-[]->(k:Keyword)
Return distinct k.name, Count(u)
Result:
cat, 10
dog, 15
06-26-2020 01:44 PM
I'm not asking for a count over each keyword. I'm asking for the number of nodes that have a keyword relationship, regardless of name
.
06-26-2020 04:44 PM
Try count(distinct u)
06-26-2020 05:24 PM
Another possibility:
MATCH (u:User)
WHERE (u)-->(:Keyword)
RETURN count(u)
Though if you know the relationship type (if only a single type connects from a :User to a :Keyword node), then you can use that in your WHERE pattern instead of the :Keyword label, and it will turn to a more efficient degree check, since a node knows what relationship types are connected to it, so you won't have to pay the cost of expanding and filtering on the label of the node on the other side.
All the sessions of the conference are now available online