Search code examples
neo4jcypher

How to delete more than one relationship in neo4j using cypher?


I want to remove more than one relationship but not all relationship for specific node,

I can delete single relationship or every relationship but not more than one specific relationship

match(n:Student{id:2),
(n)-[r1:STUDENT_CLASS]->(b:Class),
(n)-[r2:STUDENT_RANK]->(m:Rank)
delete r1,r2
return n.name

I connected Student node with 3 common nodes(School,Class,Rank) with different relationship. I want to delete 2 relationship(Class,Rank) for particular student in same query without affecting another node's(School) relationship with Student node.


Solution

  • The vertical stroke | acts as an OR operator when selecting relationships:

    match (n:Student {id:2})-[r:STUDENT_CLASS|STUDENT_RANK]->(b)
    where b:Class or b:Rank
    delete r