Creating nodes and setting up relationships

Greetings! I have a newbie cypher question on creating nodes and relationships. As a simple example I want to create a db with the following commands:

Create (:Person{Name:"Robert Plant"})-[member_of]->(:Band{Name:"Led Zeppelin"})
Create (:Person{Name:"Jimmy Page"})-[member_of]->(:Band{Name:"Led Zeppelin"})

I wind up with 2 person nodes and 2 band nodes with the same name, I want to create people and have them point to the same band node? How do I do this? Hope this makes sense.

Hi @Lucian1215,
I recommend you do the free online course provided by neo4j - online training. This will help you a lot in understanding most of the basics behind using neo4j.

As for the above problem you have to attach a variable to the band node, this is to allow the node be identified later on.

Create (:Person{Name:"Robert Plant"})-[:MEMBER_OF]->(b:Band{Name:"Led Zeppelin"})
Create (:Person{Name:"Jimmy Page"})-[:MEMBER_OF]->(b)

Hope this helps you :slight_smile:

Yes, Thank you very much for the answer and your time, Tarendran. I have gone through the tutorials and they are great but in some cases the examples are more focused on the query perspective. A good example is the "Ann" and "Dan" relationship section where they both drive a volvo. I could not find a clear explanation of how, after creating Ann, Dan, and Dan's Volvo, how to set the relationship that Ann also drives that same Volvo. I understand I should first match on Dan's Volvo and then set Ann's relationship with it.

Thank you again :slight_smile:

1 Like