i have family tree graph. there few people i'm interested in, , seeing immediate family are. have nice query return siblings of person of interest:
match (p:person)-[]-(parent:person)-[]->(parents_kids:person) p.`person_of_interest` = 'y' return p, parent, parents_kids ;
i can return children of person of interest:
match (p:person)-[]->(children:person) p.`person_of_interest` = 'y' return p, children ;
these queries work fine separately, how return results together?
the issue sometimes, people of interest don't have kids in database. on other hand, people of interest don't have parents in database. can't write 1 query match both cases.
i'm wanting simple table out...i'm thinking there null
values appropriate:
| person_of_interest | silblings | children | |--------------------|-----------|----------| | | | | | | | |
if unclear, can of course modify question minimal reproducible example. thanks!
this query should return person
of interest, , (possibly empty) collections of his: parents
, siblings
, , children
.
match (p:person {person_of_interest: 'y'}) optional match (p)<-[:has_child]-(parent:person) optional match (parent:person)-[:has_child]->(sib:person) sib <> p optional match (p)-[:has_child]->(kid:person) return p, collect(distinct parent) parents, collect(distinct sib) siblings, collect(kid) children;
the query assumes has_child
relationship type used denote parent-to-child relationship.
to speed finding of person of interest, should create index or unique constraint on :person(person_of_interest)
.
Comments
Post a Comment