cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to return nodes as threes connected with an relationship

Hi, I would like to return nodes of 3 organizations where.
FirstOrg-[:OWNS]->SecondOrg-[:OWNS]->ThirdOrg.
So returning the name of 1st org, which owns 2nd org, which owns 3th org.
So it would look like that
3X_b_0_b0e18bf9d2cf52b939a51d24603f86158ff75127.png
I tired with this: MATCH(n:Organization)-[:OWNS]->(n1:Organization)-[:OWNS]->(n2:Organization) RETURN n,n1,n2
Although it returns all nodes which are related to FirstOrg, SecondOrg, ThirdOrg. Not only the 'threes' with the pattern i wanted.
The output of the command above, which shows that some grapsh do not match the pattern i wanted:

1 REPLY 1

Hello @amf3tam1nkapvp

Can you try this?

MATCH p=(:Organization)-[:OWNS*3]->(:Organization)
RETURN p

Otherwise, in the Neo4j Desktop parameters, you can also uncheck the setting Connect result nodes.
3X_4_9_49f0cd741adfbd57496e8fac847431ed4bc3b91d.png

Additionally, the displayed result may be different from what is returned since graphical views display each node / relation once. You should check in table to see the "rigth" result.
3X_a_7_a70c495fcd572c1c37c8158686a35cdf8e2a5528.png

Regards,
Cobra