In this diagram, I would like to find the whole circle of gray nodes in the red bubble, and not in other gray nodes. That is, all nodes labeled: OTHER, which are auxiliary nodes of nodes on the path between A and C. NB. The path between A and C can be longer than the three nodes listed here.

So what I want to do is get the path p = A ... C and the subquery of each node in the path for the relation [-. HAS] → (n: OTHER).
However, I am stuck in a subquery because it does not affect the result set of the original query, but rather on all nodes.
So this gives me all the gray nodes :( and not just the ones in the red bubble. Please help
match p=(n:MAIN)-[:EXTENDS*]->(m:MAIN)
where n.name = 'A' AND m.name='C'
WITH nodes(p) AS collection
match (l:MAIN)-[:HAS]->(u:OTHER) return u; //This last part is my subquery
source
share