# Should I must have a relational CSV to build the relation?

**URL:** <https://community.neo4j.com/t/should-i-must-have-a-relational-csv-to-build-the-relation/13059>\
**Category:** Cypher\
**Tags:** cypher, import\
**Created:** [December 21, 2019, 2:19pm UTC](https://community.neo4j.com/t/should-i-must-have-a-relational-csv-to-build-the-relation/13059 "2019-12-21T14:19:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsutong](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wsutong/32/8172_2.png) [@wsutong](https://community.neo4j.com/u/wsutong)\
**Post date:** [December 21, 2019, 2:19pm UTC](https://community.neo4j.com/t/should-i-must-have-a-relational-csv-to-build-the-relation/13059/1 "2019-12-21T14:19:00Z")

</div>

I have build a toy database , with _Stock_ and _Industry_.  
Basically I have 25 Industry and about 8000 Stock. I want to create a link from the stock to industry.

I have a stock.csv with

```auto
stock_id, setupDate, name ....

```

and a stock\_industry.csv with

```auto
stock_id, name, c_name

```

Then I first create nodes with Stock by the following:

```auto
USING PERIODIC COMMIT 300
LOAD CSV WITH HEADERS FROM "file:///stock.csv" AS stock_industry

MERGE (s:Stock { stock_id:stock_industry.stock_id ... })
RETURN count(s)

```

I then create the the industry nodes with only the industry name.

Then I want to create a "is\_industry\_of" relationship between the industry nodes and stock nodes:

```auto
LOAD CSV WITH HEADERS FROM "file:///stock_industry.csv" AS stock_industry
MATCH (s:Stock),(i:Industry)
WHERE s.stock_code=stock_industry.code AND i.industry=stock_industry.c_name
CREATE (s)-[r:is_industry_of]->(i)
RETURN count(s)

```

Then I got 0 results.

I searched the Internet, everyone has the third csv file as the relationship between "stock\_code, industry\_name".

However, I have a csv with the "stock\_code, stock\_name, industry\_name".  
Should I just use this csv and avoid using the relation-database-like one?

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [December 21, 2019, 2:22pm UTC](https://community.neo4j.com/t/should-i-must-have-a-relational-csv-to-build-the-relation/13059/2 "2019-12-21T14:22:51Z")

</div>

You've just got this piece the wrong way around. Rather than doing this:

> [@wsutong](#):
>
> LOAD CSV WITH HEADERS FROM "file:///stock\_industry.csv" AS stock\_industry MATCH (s:Stock),(i:Industry) WHERE s.stock\_code=stock\_industry.code AND i.industry=stock\_industry.c\_name CREATE (s)-[r:is\_industry\_of]-\>(i) RETURN count(s)

You should do this:

```auto
LOAD CSV WITH HEADERS FROM "file:///stock_industry.csv" AS stock_industry
MATCH (s:Stock { id: stock_industry.id })
MERGE (i:Industry { name: stock_industry.name, c_name: stock_industry.c_name })
MERGE (s)-[:is_industry_of]->(i)
RETURN count(i);

```

---

<div class="post-metadata">

**Author:** ![wsutong](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/wsutong/32/8172_2.png) [@wsutong](https://community.neo4j.com/u/wsutong)\
**Post date:** [December 21, 2019, 3:20pm UTC](https://community.neo4j.com/t/should-i-must-have-a-relational-csv-to-build-the-relation/13059/3 "2019-12-21T15:20:00Z")

</div>

Thanks! Problem perfectly solved!
