# Merge Nodes based on condition on relationship property

**URL:** <https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294>\
**Category:** Neo4j Graph Platform\
**Tags:** apoc, cypher\
**Created:** [March 3, 2020, 5:46pm UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294 "2020-03-03T17:46:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lkulageri](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lkulageri/32/9484_2.png) [@lkulageri](https://community.neo4j.com/u/lkulageri)\
**Post date:** [March 3, 2020, 5:46pm UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/1 "2020-03-03T17:46:43Z")

</div>

I started using neo4j recently.I have a scenario like

Match (a:parent)-[r:father\_of]-\>(b:daughter)-[r1:friend\_of{talks\_to:5 times}]-\>(c:daughter)-[r2:daughter\_of]-\>(d:parent)

Now I want to marge all these nodes to one if talks\_to property of r1 relationship is more that 2 times.Or create one master node to all these, like all these belong to that family if it meets given condition.How this can be done

---

<div class="post-metadata">

**Author:** ![MuddyBootsCode](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/muddybootscode/32/10330_2.png) [@MuddyBootsCode](https://community.neo4j.com/u/MuddyBootsCode)\
**Post date:** [March 3, 2020, 6:48pm UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/2 "2020-03-03T18:48:32Z")

</div>

Have you checked out the APOC merge nodes procedure? [15.3.&nbsp;Merge Nodes - Chapter&nbsp;15.&nbsp;Graph Refactoring](http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/graph-refactoring/merge-nodes/) It might be what you're looking for.

---

<div class="post-metadata">

**Author:** ![lkulageri](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lkulageri/32/9484_2.png) [@lkulageri](https://community.neo4j.com/u/lkulageri)\
**Post date:** [March 4, 2020, 4:55am UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/3 "2020-03-04T04:55:32Z")

</div>

Yeah I already used that but now I want to merge parent nodes based on child node properties

---

<div class="post-metadata">

**Author:** ![intouch\_vivek](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/intouch_vivek/32/4097_2.png) [@intouch\_vivek](https://community.neo4j.com/u/intouch_vivek)\
**Post date:** [March 4, 2020, 8:01am UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/4 "2020-03-04T08:01:56Z")

</div>

I guess you are trying to merge nodes based on the Relationship property of [friend\_of]

Match (a:parent)-[r:father\_of]-\>(b:daughter)-[r1:friend\_of]-\>(c:daughter)-[r2:daughter\_of]-\>(d:parent)  
Where toInteger(split(r1.talks\_to,' ')[0]) \>'2'

---

<div class="post-metadata">

**Author:** ![lkulageri](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lkulageri/32/9484_2.png) [@lkulageri](https://community.neo4j.com/u/lkulageri)\
**Post date:** [March 4, 2020, 10:03am UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/5 "2020-03-04T10:03:24Z")

</div>

Yes Exactly this is what I am trying...but how to merge a,d based on that

---

<div class="post-metadata">

**Author:** ![intouch\_vivek](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/intouch_vivek/32/4097_2.png) [@intouch\_vivek](https://community.neo4j.com/u/intouch_vivek)\
**Post date:** [March 4, 2020, 10:23am UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/6 "2020-03-04T10:23:25Z")

</div>

Could you please give me small sample data set

---

<div class="post-metadata">

**Author:** ![lkulageri](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lkulageri/32/9484_2.png) [@lkulageri](https://community.neo4j.com/u/lkulageri)\
**Post date:** [March 4, 2020, 11:45am UTC](https://community.neo4j.com/t/merge-nodes-based-on-condition-on-relationship-property/15294/7 "2020-03-04T11:45:21Z")

</div>

(a:parent)-[r:father\_of]-\>(b:daughter)-[r1:friend\_of{talks\_to:5 times}]-\>(c:daughter)-[r2:daughter\_of]-\>(d:parent)

(a:parent)-[rr:father\_of]-\>(e:daughter)-[rr1:friend\_of{talks\_to:4 times}]-\>(f:daughter)-[rr2:daughter\_of]-\>(g:parent)

(g:parent)-[rrr:father\_of]-\>(h:daughter)-[rrr1:friend\_of{talks\_to:1 times}]-\>(i:daughter)-[rr2:daughter\_of]-\>(n:parent)

See above is my data set.Now I want to merge a,d,g nodes because their talks\_to is more than 2 and n should be seperate node because g -\> n talks\_to is less than 2
