How to limit query results by count of node type

Hey all!

I'm running the following query, but getting errors, and I'm not sure why since it conceptually makes sense to me:

MATCH (p:Person)-[:HAS_CONTACT_RECORD]->(c:Contact)-[:HAS_EMAIL]->(c2:PrimaryEmail)

WHERE count(c)>2

RETURN *

this is my schema,

and this is what the query returns when I exclude the "where clause". What I want is to be able to see only the people and PrimaryEmails related to more than 2 Contacts (the green nodes). So in the image below, assuming the query worked as expected, I would have only seen the piece in the upper center with the name "Steve Zoelick"

Let me know what the proper and most efficient way to do this is!

Thanks guys!

GQ

Hello @gq16 :blush:

You can't directly use an aggregating function in the WHERE clause.

MATCH (p:Person)-[:HAS_CONTACT_RECORD]->(c:Contact)-[:HAS_MAIL]->(e:PrimaryEmail)
WITH p, collect(c) AS contacts, collect(e) AS emails
WHERE size(contacts) > 2
RETURN *

Regards,
Cobra