cancel
Showing results forΒ
Did you mean:Β

## 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:

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
``````

Identify the children records:

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

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.

Ninja

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

Nodes 2022

NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Neo4j Resources