How to specify more than two relationships to the same node in a `MERGE`
13:31 13 Nov 2025

I have this situation

CREATE (a:X { id: 1 })
CREATE (b:Y { id: 2 })
CREATE (c:Z { id: 3 })
CREATE (:Z { id: 4 })
CREATE (a)-[:HAS]->(d:W { id: 5 })<-[:HAS]-(b)
CREATE (c)-[:HAS]->(d)

Initial situation

And I want to run this query

MATCH (a:X { id: 1 })
MATCH (b:Y { id: 2 })
MATCH (c:Z { id: 4 }) // The one with no relationships yet
MERGE (a)-[:HAS]->(d:W)<-[:HAS]-(b), (d)<-[:HAS]-(c)
ON CREATE SET d.id = 6

The problem is that I'm not allowed to put more than one path in a single MERGE, how can I do this?

This is the result I want to achieve

Expected result

Notice that I can't just do this

MATCH (a:X { id: 1 })
MATCH (b:Y { id: 2 })
MATCH (c:Z { id: 4 })
MERGE (a)-[:HAS]->(d:W)<-[:HAS]-(b) // This path already exists, but it uses the other `Z`
ON CREATE SET d.id = 6
MERGE (d)<-[:HAS]-(c) // Separate merge

Because the result would be

What I don't want

neo4j cypher