Reputation: 791
I would like to specify a node and return all the relationships that the node has, along with every other relationships that are connecting the rest of the nodes.
An example of what I would like to return is:
Eric, PARENT_OF, Mia
Eric, PARENT_OF, Peter
Mia, SIBLING_OF, Peter
Mia, SPOUSE_OF, Mark
...
Assuming that the specified node is Eric
, they query should return all the relationships that are directly connected to him along with the relationships that are not connected to Eric
but are connected to some of his connected nodes.
Upvotes: 3
Views: 860
Reputation: 16375
I have simulated your scenario with this data set:
CREATE (eric:Person {name:'Eric'})
CREATE (mia:Person {name:'Mia'})
CREATE (peter:Person {name:'Peter'})
CREATE (mark:Person {name:'Mark'})
CREATE (eric)-[:PARENT_OF]->(mia)
CREATE (eric)-[:PARENT_OF]->(peter)
CREATE (mia)-[:SIBLING_OF]->(peter)
CREATE (mia)-[:SPOUSE_OF]->(mark)
The below query should work to achieve your goal:
MATCH (root:Person {name:'Eric'})-[r*1..3]->(a:Person)
UNWIND r AS rs
RETURN DISTINCT startNode(rs).name, type(rs), endNode(rs).name
As result:
╒════════════════════╤════════════╤══════════════════╕
│"startNode(rs).name"│"type(rs)" │"endNode(rs).name"│
╞════════════════════╪════════════╪══════════════════╡
│"Eric" │"PARENT_OF" │"peter" │
├────────────────────┼────────────┼──────────────────┤
│"Eric" │"PARENT_OF" │"Mia" │
├────────────────────┼────────────┼──────────────────┤
│"Mia" │"SIBLING_OF"│"peter" │
├────────────────────┼────────────┼──────────────────┤
│"Mia" │"SPOUSE_OF" │"Mark" │
└────────────────────┴────────────┴──────────────────┘
Upvotes: 4