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.

Creating Relationship between nodes.

I have a data like below

vence_andersen1_1-1662371548115.png

Here I am trying to merge all values of Alpha with all values of Beta. Example I want a relationship between a-z, a-y, a-x, a-w, a-v then b-z, b-y, b-x, b-w, b-v and so for the rest. 

Can I achieve this using the queries? Thanks in advance.

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

One approach would be to collect both columns into lists and use a double unwind to get the Cartesian product of the two lists. This would allow you to relate each pair of elements from both lists. 

Something like this: 

load csv with headers from “file:///Data.csv” as line

with collect(line.Alpha) as alpha, collect(line.Beta) as beta

unwind alpha as a

merge(n:NodeType{id: a})

unwind beta as b

merge(m:NodeType{id: b})

merge(n)-[:HAS_REL]->(m)

 

 

View solution in original post

1 REPLY 1

glilienfield
Ninja
Ninja

One approach would be to collect both columns into lists and use a double unwind to get the Cartesian product of the two lists. This would allow you to relate each pair of elements from both lists. 

Something like this: 

load csv with headers from “file:///Data.csv” as line

with collect(line.Alpha) as alpha, collect(line.Beta) as beta

unwind alpha as a

merge(n:NodeType{id: a})

unwind beta as b

merge(m:NodeType{id: b})

merge(n)-[:HAS_REL]->(m)