VOOZH about

URL: https://www.geeksforgeeks.org/dbms/neo4j-create-relationship/

⇱ Neo4j Create Relationship - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Neo4j Create Relationship

Last Updated : 13 Sep, 2022

In Neo4j to create relationship between nodes you have to use the CREATE statement like we used to create nodes. lets create relation between two already created nodes. Example:

  • Already created nodes: 👁 Image
  • Query to create relation:
$ MATCH (a:GeeksforGeeks), (b:W3School)
WHERE a.Name = "A Computer Science Portal" AND b.Name = "We are the Learner"
CREATE (a)-[r:edutech]->(b)
RETURN r
  • Output of above query: 👁 Image
  • Creating a new node:
$ CREATE (c:Company { Name: "Tutorial" })
MATCH (a:GeeksforGeeks), (b:W3School), (c:Comapny)
WHERE a.Tag = "A Computer Science Portal" AND b.Tag = "We are the Learner" AND 
c.Name = "Tutorial" CREATE (c)-[pr:PRODUCED]->(b), (c)-[pr1:PROVIDER]->(a)
RETURN a, b, c
Comment
Article Tags:
Article Tags:

Explore