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.

What it means to connect two nodes without a relation?

I have written below three queries and trying to understand difference between all 3 of them.

Query1:

MATCH (person)-[r]->(otherPerson)

Query2:

MATCH (person)-->(otherPerson)

Query3:

MATCH (person)--(otherPerson)

Please let me know if there is any difference between the three queries.

1 ACCEPTED SOLUTION

All three describe a direct relationship between a person node and an otherPerson node and the relationship type is not specified, i.e, a single relationship between the two nodes of any type.

The differences are:
Q1: specifies a direction and binds the relationship to a variable ‘r’, so that it can be referenced in your query. Variables are only needed if you need to reference the object.

Q2: specifies a directed relationship and does not bind the relationship to a variable. This is shorthand notation for (person)-->(otherPerson)

Q3: does not specify a direction, so relationships in either direction will match. This is shorthand for (person)--(otherPerson)

Hope this helps.

Sections 3-6 may help too.

View solution in original post

1 REPLY 1

All three describe a direct relationship between a person node and an otherPerson node and the relationship type is not specified, i.e, a single relationship between the two nodes of any type.

The differences are:
Q1: specifies a direction and binds the relationship to a variable ‘r’, so that it can be referenced in your query. Variables are only needed if you need to reference the object.

Q2: specifies a directed relationship and does not bind the relationship to a variable. This is shorthand notation for (person)-->(otherPerson)

Q3: does not specify a direction, so relationships in either direction will match. This is shorthand for (person)--(otherPerson)

Hope this helps.

Sections 3-6 may help too.