Reputation: 35
New to Neo4j and looking for AND clause in a Cypher query. Suppose I have Person nodes and Role nodes. A person can have multiple Roles (Manager, Leader, IC, QA,...) I want to find the set of People who have both the roles of Manager and QA.
Somethng like: MATCH (p:Person)-[:HAS_ROLE]->(r:Role{name:"Manager"}) AND (p)-[:HAS_ROLE]->(r:Role{name:"QA"}) RETURN p
Upvotes: 0
Views: 187
Reputation: 510
MATCH (p:Person)-[:HAS_ROLE]->(:Role{name:"Manager"})
WHERE (p)-[:HAS_ROLE]->(:Role{name:"QA"})
RETURN p
this above query can be used if its just two Roles.But if want try for Many,then
MATCH (p:Person)-[:HAS_ROLE]->(r:Role)
WITH p, COLLECT(r.name) as roles
WHERE ALL (x IN ["Manager","QA"] WHERE x IN roles)
RETURN p
you can update this ["Manager","QA"]
with all the roles you want to check for a person.
Upvotes: 1