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.andersen17

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

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

Yours kindly,
Omer