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.

How to create relationship from csv without using node

i have a csv file
name college
ABC clg1
BCD clg2

i want a relation from name->clg
how can i create that without using any nodes .

2 REPLIES 2

Impossible. Relationships can only connect nodes, they always have a start node and an end node, though it could be that they are the same node (a relationship from a node that points to itself).

In case I misunderstood, you might want to clarify what you're trying to do.

It may help to start out with an example based on your data. I'm guessing at what your data model might look like, but try these in an empty neo4j database. I used neo4j desktop to create an empty graph db.

// create the first relationship
create p=(:person {name:'ABC'})-[:ATTENDING]->(:college {name:'clg1'})
return p

// create the second relationship
create p=(:person {name:'BCD'})-[:ATTENDING]->(:college {name:'clg2'})
return p

// return all people and the college they are attending
match p=(a:person)-[:ATTENDING]->(b:college)
return p

// add another person 'me' ATTENDING clg2 (an existing college)
Match (b:college {name:'clg2'})
CREATE p=(a:person {name:'me'})-[:ATTENDING]->(b)
return p

// return all people and the college they are attending, again to see there are now two people attending clg2
match p=(a:person)-[:ATTENDING]->(b:college)
return p

notes

  • this is a trivial example to get you started
  • the third CREATE cypher demonstrates finding an exist node in the graph before creating a new relationship to avoid creating a duplicate copy of the college node.
  • If you don't know if a node or relationship exists yet, the MERGE command will be useful