Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-25-2019 04:53 AM
Hi,
I have Graph like this below.
A-[:x]->B-[:y]->C-[:z]->D
Assume I dont know what relation exists between A and D, but I know A and D are related. I want to write a dynamic query which can detect A.name connected to d.name="XXX" without writing the relations between A to D.
I tried something like this but it is not giving correct results. I am expecting A nodes whcih are related to d,name="HEN" but I am getting all A nodes related to D nodes.
MATCH (a:A),(d:D {name:"HEN"}), p = shortestPath((a)-[ * ]-(d))
RETURN distinct a,p,d
Can you let me know how can I achieve this. I want to identify the relation between two nodes first and using that relation between two nodes I want to find out result.
Thanks in Advance
Solved! Go to Solution.
11-25-2019 05:24 AM
MATCH p=(start:A { name: "Starting Point" })-[*]->(end:D { name: "Ending Point" })
RETURN p;
The use of the -[*]->
will match any set of relationships of any type in any order or length. It'll find a path from A to D for you. All of this gets put into a "path variable" called p which gets returned. You can use list functions to then extract out of that all of the nodes and relationships in the middle, if you wish.
11-25-2019 05:24 AM
MATCH p=(start:A { name: "Starting Point" })-[*]->(end:D { name: "Ending Point" })
RETURN p;
The use of the -[*]->
will match any set of relationships of any type in any order or length. It'll find a path from A to D for you. All of this gets put into a "path variable" called p which gets returned. You can use list functions to then extract out of that all of the nodes and relationships in the middle, if you wish.
04-02-2020 08:45 AM
I have a relationship as
A-[:x]->B-[:y]->C
OR
A-[:x]->C
Does the above solutions holds true for this situation as well.... I haven't tried yet though. (Will do in couple of days)
All the sessions of the conference are now available online