# How to fuse same nodes

**URL:** <https://community.neo4j.com/t/how-to-fuse-same-nodes/8207>\
**Category:** Cypher\
**Created:** [June 20, 2019, 1:12pm UTC](https://community.neo4j.com/t/how-to-fuse-same-nodes/8207 "2019-06-20T13:12:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axel.nardin](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/axel.nardin/32/5328_2.png) [@axel.nardin](https://community.neo4j.com/u/axel.nardin)\
**Post date:** [June 20, 2019, 1:12pm UTC](https://community.neo4j.com/t/how-to-fuse-same-nodes/8207/1 "2019-06-20T13:12:16Z")

</div>

Hello, I have a problem :

I'm working on a Graph with Countries of the world  
I use this Cypher command :

```auto
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
create (cap:Capitale {name: line.capital})
create (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
create (cont:Continent {name: line.continent})
create (o:Ocean {name: line.ocean})
create (i:Iles {name: line.iles})	
create (org:Organisme {name: line.organisme})
create (langPrinc:LanguePrincipale {name: line.languePrincipale})
create (langSec:LangueSecondaire {name: line.autreLangue})
create (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
create (gouv:Gouvernance {name: line.gouvernance})
create (m:Monnaie {name: line.monnaie})
create (dev:Devise {name: line.devise})

create (cap)-[:CAPITALE_DE]->(p)
create (langPrinc)-[:SPOKE]->(p)
create (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
create (o)-[:BORDE]->(p)
create (p)-[:POSSEDE]->(i)
create (d)-[:DIRIGE]->(p)
create (m)-[:EST_LA_MONNAIE]->(p)
create (dev)-[:EST_LA_DEVISE]->(p)
create (p)-[:EST_SUR_CONTINENT]->(cont)
create (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
create (dir)-[:MEMBRE_DE]->(org) 
create (gouv)-[:SIEGE_A]->(cap)

```

When i start a Query to find all countries which speak english, I use this query : (Country)-[SPOKE]-\>(English)

The problem is : instead of creating one node with the langage ( here english ), and all the countries which speak this language around, it creates me tons of "english" node, each one linked to only one country

I use an CSV file to organise my data. And i already try to remplace all my CREATE by MERGE but i have an error : Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for name.

So i'm really stuck,  
Thank for your help , I'm not english, if you need more distinct info, I can try again to explain

---

<div class="post-metadata">

**Author:** ![elaine\_rosenber](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/elaine_rosenber/32/27409_2.png) [@elaine\_rosenber](https://community.neo4j.com/u/elaine_rosenber)\
**Post date:** [June 20, 2019, 2:01pm UTC](https://community.neo4j.com/t/how-to-fuse-same-nodes/8207/2 "2019-06-20T14:01:26Z")

</div>

You definitely should use MERGE to create the relationships and ideally the nodes also, this will prevent duplicates.

From the error you are seeing, there is data in your CSV file that has no value for name. This is not allowed in a MERGE. Can you clean up the data?

Ideally, you want uniqueness constraints on all of the properties you are using the create the nodes.

Elaine

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [June 20, 2019, 10:37pm UTC](https://community.neo4j.com/t/how-to-fuse-same-nodes/8207/3 "2019-06-20T22:37:23Z")

</div>

Your test.csv file has null/no data for one or more columns on any row. There are two ways to handle this.

1. If you do not want import the whole row with column(s) with null/no data then:  
Example: line.pays has no value and you want to skip this row

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line  
WITH line WHERE line.pays is NOT NULL

MERGE (cap:Capitale {name: line.capital}).......  
MERGE (gouv)-[:SIEGE\_A]-\>(cap)

1. If you want to include rows with some null value columns then  
Example: line.languePrincipale = ""

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line  
WITH line

MERGE (cap:Capitale {name: line.capital})  
MERGE (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })  
MERGE (cont:Continent {name: line.continent})  
MERGE (o:Ocean {name: line.ocean})  
MERGE (i:Iles {name: line.iles})   
MERGE (org:Organisme {name: line.organisme})

// when line.languePrincipale has some value......

FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NOT NULL THEN [1] ELSE END |

MERGE (langPrinc:LanguePrincipale {name: line.languePrincipale})  
MERGE (langPrinc)-[:SPOKE]-\>(p)

)

// when line.languePrincipale has no value...... NA (Not Available). Use this if you want to create language node with NA value.

FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NULL THEN [1] ELSE END |

MERGE (langPrinc:LanguePrincipale {name: "NA"})  
MERGE (langPrinc)-[:SPOKE]-\>(p)

)

MERGE (langSec:LangueSecondaire {name: line.autreLangue})  
MERGE (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})  
MERGE (gouv:Gouvernance {name: line.gouvernance})  
MERGE (m:Monnaie {name: line.monnaie})  
MERGE (dev:Devise {name: line.devise})

MERGE (cap)-[:CAPITALE\_DE]-\>(p)  
MERGE (langPrinc)-[:SPOKE]-\>(p)  
MERGE (langSec)-[:LANGUES\_SECONDAIRES\_PARLEE]-\>(p)  
MERGE (o)-[:BORDE]-\>(p)  
MERGE (p)-[:POSSEDE]-\>(i)  
MERGE (d)-[:DIRIGE]-\>(p)  
MERGE (m)-[:EST\_LA\_MONNAIE]-\>(p)  
MERGE (dev)-[:EST\_LA\_DEVISE]-\>(p)  
MERGE (p)-[:EST\_SUR\_CONTINENT]-\>(cont)  
MERGE (p)-[:TYPE\_DE\_GOUVERNANCE]-\>(gouv)  
MERGE (dir)-[:MEMBRE\_DE]-\>(org)  
MERGE (gouv)-[:SIEGE\_A]-\>(cap);

---

<div class="post-metadata">

**Author:** ![axel.nardin](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/axel.nardin/32/5328_2.png) [@axel.nardin](https://community.neo4j.com/u/axel.nardin)\
**Post date:** [June 21, 2019, 8:19am UTC](https://community.neo4j.com/t/how-to-fuse-same-nodes/8207/4 "2019-06-21T08:19:56Z")

</div>

Thank a lot you solve my problem !
