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.

Delete extra relationships

tideon
Graph Buddy

Dear Community,

I ran a cypher query that created 19 relationships, but I only need of relationship. So it created 19 SOLD_BY relationships.

How do I get neo4J to delete all but of relationship of SOLD_BY?

Thank you in advance

1 REPLY 1

this looks like already asked and described at

https://groups.google.com/forum/#!topic/neo4j/VqD2dX41yc8

and in short, for example

create (n:X {id:1});
create (n2: Y {id:2});
match (n:X),(n2:Y) create (n)-[:FOLLOWS]->(n2);
match (n:X),(n2:Y) create (n)-[:FOLLOWS]->(n2);
match (n:X),(n2:Y) create (n)-[:FOLLOWS]->(n2);
match (n:X),(n2:Y) create (n)-[:FOLLOWS]->(n2);
// at this point the :X node has multiple :FOLLOWS relationship to :Y node
// display such multiple relationships
match (n:X)-[r:FOLLOWS]->(n2:Y) return n, r, n2;
// delete all but 1
match (n:X)-[r:FOLLOWS]->(n2:Y) with r skip 1 delete r;

does this address your issue?