I'm trying to figure out what I assume is a very simple cypher code. I have a list of companies, a list of codes and a list of departments. I use merge for companies and codes, but I would like for the departments to be unique for each code even though they repeat, my data looks like this:
Company A Code 1 Finance
Company A Code 1 Finance
Company A Code 1 Finance
Company A Code 1 Sales
Company A Code 1 HR
Company B Code 11 Finance
Company B Code 12 Sales
Company B Code 13 HR
Company,Code,Department
Company A,Code 1,Finance
Company A,Code 1,Finance
Company A,Code 1,Finance
Company A,Code 1,Sales
Company A,Code 1,HR
Company B,Code 11,Finance
Company B,Code 12,Sales
Company B,Code 13,HR
I changed your Cypher code to look like this.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///Output.csv' as line
MERGE (c:Company { name: toUpper(line.Company) })
MERGE (co:Code { name: toUpper(line.Code) })
MERGE (c)-[:HAS_CODE]->(co)
MERGE (dep:Department { name: toUpper(line.Department) })-[:BELONGS_TO]->(co)
As a result, the Finance of Code1 of Company is one.
Is this image the same as your data model?