sprint_6
sprint_6

Reputation: 81

Neo4j cypher: Return all nodes that are connected to two nodes and two nodes only

I have a Neo4j graph that looks like this: enter image description here

How do I write my Cypher query so that I return all persons who are only part of this combination of groups (Ethnicity & Age). The query should result in 4 Person nodes, Bob, John, Carl, and Dan. Brian is part of only one of these groups (age) so he needs to be excluded.

Thanks in advance.

Upvotes: 0

Views: 604

Answers (1)

Graphileon
Graphileon

Reputation: 5385

This MATCH returns the person name and the names of their categories for those who have both.

MATCH (e:Group {name:'Ethnicity'})-->(ec:Category)-->(p:Person)<--(ac:Category)<--(a:Group {name:'Age'}) 
RETURN p.name,ac.name,ec.name

Upvotes: 2

Related Questions