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.

CREATE command returned a relationship that wasn't mentioned in RETURN command

Hello,
I am going through the Getting Started docs and As I was trying the last Cypher example, which is:

CREATE (a:Person { name:"Tom Hanks",
  born:1956 })-[r:ACTED_IN { roles: ["Forrest"]}]->(m:Movie { title:"Forrest Gump",released:1994 })
CREATE (d:Person { name:"Robert Zemeckis", born:1951 })-[:DIRECTED]->(m)
RETURN a,d,r,m

I found that the :DIRECTED relationship is returned and displayed although it is not mentioned in the return statement.
Can anyone explain why is that?
I know that it was created because we specified that in the second CREATE command and we didn't give it a variable.
But my question is why it has been RETURNed? Is that the case that whenever we RETURN any two nodes (m and d in this example), the relationship(s) between them are being returned by default?

Thank you in advance.

2 REPLIES 2

Hi,

the relationship between nodes is not always returned. In your case you can suppress the output of the relationship when you uncheck the "Connect result nodes" checkbox in the browser settings.

3X_5_9_59d50e1086e71889419f1c5d4932166c36f95b71.png

To add more context, the "Connect result nodes" feature in the browser can be useful when exploring your data, as it queries for and gives back all the relationships that exist between the nodes returned even if you didn't ask for them. Obviously in cases where you want only specific relationships, it's going to interfere with the graphical results, so uncheck it for those queries.