Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create more than one label to a single relation in cypher query

Tags:

neo4j

cypher

Currently i am working with graph db. I have two nodes and i need to create more than one label to the same relation. Is it possible to create more than one label to a relationship in cypher query? I tried this, but not working:

START n=node(1), n1=node(2) CREATE UNIQUE (n)-[r:HAS_TEST:HAS_ATTENDED]->(n1) return n,n1;

If it is possible, how? If it is not possible why?

like image 949
Science Avatar asked Dec 07 '25 02:12

Science


1 Answers

A relationship has a single type, so you cannot do what you've asked. Instead, create two relationships:

START n=node(1), n1=node(2)
CREATE UNIQUE (n)-[:HAS_TEST]->(n1)
CREATE UNIQUE (n)-[:HAS_ATTENDED]->(n1)
RETURN n,n1;

Or create a new relationship type that implies both HAS_TEST and HAS_ATTENDED.

like image 186
Luanne Avatar answered Dec 09 '25 00:12

Luanne