How to create the same node from two different columns and create relationships,

Hi,

I am trying to load data from a csv file with two columns of people and I want to capture the relationship between them if they are on the same row. I cannot figure out how to create the same node even if the person appears in different columns:

|Person| Friend|
|Joe Bloggs| Jane Bloggs|
|Jane Bloggs| John H|

so Jane Bloggs should only appear as one node.

I got to this point but this will create two different nodes for Jane:

LOAD CSV WITH HEADERS FROM "file:///friends.csv" as friends
WITH friends
WHERE friends.Person IS NOT NULL
MERGE (p:person {Name:friends.Person})
MERGE (f:friend {Name:friends.Friend})
MERGE (p)-[:knows]->(f)

It looks like it should create both nodes because they are MERGEd using different labels, right?

Have you thought about or tried using the :person label for all people? I think that is how I might model this, the relationship would indicate the friend status... Simplistically, something like this

LOAD CSV WITH HEADERS FROM "file:///friends.csv" as friends
WITH friends
WHERE friends.Person IS NOT NULL
MERGE (p:person {Name:friends.Person})
MERGE (f:person {Name:friends.Friend})
MERGE (p)-[:knows]->(f)
1 Like

Thank you Joel, that worked!