cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

return the start node and end node of every realtions

saisannihith741
Node Clone

HI all,

I need to update this query so that its returns the start node and end node of  every realtionships the below is returning and also some  properties of those start and end nodes

match p = (a:MatPlant)-[r*0..20]->(b:MatPlant) where b.matl_num='428en11201' and b.plnt_cd = 'US456789033' return p
Could anyone please help
1 ACCEPTED SOLUTION

You can use this

match p = (a:MatPlant)-[*0..20]->(b:MatPlant) 
where b.matl_num='428en11201' and b.plnt_cd = 'US456789033' 
unwind relationships(path) as r
return type(r), startNode(r).matl_num, endNode(r).plnt_cd

// or

match p = (a:MatPlant)-[*0..20]->(b:MatPlant) 
where b.matl_num='428en11201' and b.plnt_cd = 'US456789033' 
unwind relationships(path) as r
with r, startNode(r) as start, endNode(r) as end
return type(r), start { .* } as startProps, end {.*, .plnt_cd} as endProps

View solution in original post

1 REPLY 1

You can use this

match p = (a:MatPlant)-[*0..20]->(b:MatPlant) 
where b.matl_num='428en11201' and b.plnt_cd = 'US456789033' 
unwind relationships(path) as r
return type(r), startNode(r).matl_num, endNode(r).plnt_cd

// or

match p = (a:MatPlant)-[*0..20]->(b:MatPlant) 
where b.matl_num='428en11201' and b.plnt_cd = 'US456789033' 
unwind relationships(path) as r
with r, startNode(r) as start, endNode(r) as end
return type(r), start { .* } as startProps, end {.*, .plnt_cd} as endProps