Connect one node to multiple nodes

Hi Everyone,

I have a problem with connecting duplicate values together and create a Master/Child relationship. I was able to solve the issue when there is only one duplicate node for each original (master) record. When there are 2 or more duplicates, things get messy.

To make things simple, I have queried the following nodes:

image

I want Three OUT [MASTER_OF] relation to go from one node to the three other nodes

What I did until now is to identify the master node and I did it using the following:

MATCH (i:INTID{name:"575"})
MATCH (n:PERSON)-[]->(i)
WITH n ORDER BY n.overall DESC limit 1
RETURN n

image

Identify the children records:

MATCH (i:INTID{name:"575"})
MATCH (n:PERSON)-[]->(i)
WITH n ORDER BY n.overall DESC SKIP 1
RETURN n

image

But then I can't proceed from here.

I was thinking of trying to combining both queries in certain way. Using FOREACH on the child records to iterate through the nodes and create a MASTER_OF relationship between master node and children node.

I am having a difficult time understanding your data, but I will assume the following. You have multiple nodes connected to a root node, which you are identifying as a node with label INTID and name property equal to "575". You want to form a parent/child relationship among the nodes connected to the root node, where the parent is the node with the highest overall property value, and the remaining nodes are children connected to the parent with an outgoing MASTER_OUT relationship to the parent. If this is correct, I believe the following query will form the parent/child relationship for the given root node. If not correct, please correct my misunderstanding of your data and I will try to adjust the query.

match (n:PERSON)-->(i:INTID{name:"575"})
with n
order by n.overall desc
limit 1
with n
match (m:PERSON)-->(i:INTID{name:"575"}) where m<>n
with n, m
merge (m)-[:MASTER_OUT]->(n)
return n,m