Remove duplicate links between nodes

For instance there are like 500 nodes connected to a node "X", the node "X" is connected to node "Y", between node "X" and "Y" there are 500 strings/relationship lines. I know the reason it occurs, but can I have one string/relationship line instead of 500 strings between 2 nodes?

Thanks in advance.

@vence_andersen1

You could try something like this:

match (p:X)-[rel]->(q:Y) // match rels
with p, q, tail(collect(rel)) as rels // with tail we pick all rels except the first one
foreach(x in rels | delete x) // remove all rels except the 1st
1 Like

Maybe it is also possible to prevent the creations of these relation with use of MERGE.

Yours kindly,
Omer

I am actually creating nodes with merge, how do you suggest it to do?

Sorry, I am confused. Do you want help avoiding the creation of the 500 relationships? If so, can you provide the code that creates the relationships?