Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-05-2022 02:55 AM
I have a data like below
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.
Solved! Go to Solution.
09-05-2022 04:58 AM - edited 09-05-2022 05:02 AM
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)
09-05-2022 04:58 AM - edited 09-05-2022 05:02 AM
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)
All the sessions of the conference are now available online