2
votes

My database structure is like A->B->C->D There are multiple relations between all nodes. I need to query data so that it can give me all nodes & all relationships in between nodes. My sample query is like A-[*]-D

The output I'm expecting is all relations and nodes between A to D which is B & C. Is there any way to do so? Thanks

1

1 Answers

1
votes

There are a few things that you can do. The first thing that you'll want to do is assign a path variable like this:

MATCH path=(a:A)-[*]-(b:B)-[*]-(c:C)-[*]-(d:D)

Then you can either get the nodes, the relationships, or the whole path like this:

MATCH path=(a:A)-[*]-(b:B)-[*]-(c:C)-[*]-(d:D)
RETURN nodes(path), rels(path), path

Depending on how you're getting data from Neo4j what is returned in the third column (the path) will vary, but generally it should be a list of node, rel, node, rel, etc... and always starting and ending with a node.