Merge multiple nodes on property

  • WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"orderinfo") YIELD row MERGE(order:Order {orderNumber:toInteger(row.orderNumber), customerNumber:toInteger(row.customerNumber), productCode:row.productCode});

WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"customerinfo") YIELD row MERGE(customer:Customer{customerNumber:row.customerNumber, ContactName: row.ContactName});

WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"productinfo") YIELD row MERGE (product:Product {productCode: row.productCode, productLine:row.productLine});

WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url CALL apoc.load.jdbc(url,"orderinfo") YIELD row MERGE (a:Order {orderNumber: toInteger(row.orderNumber)}) MERGE (b:Product {productCode: row.productCode}) MERGE (a)-[:PRODUCT]->(b);

so when i hover over the product relationship, i do not see the productLine which is a property belonging to the product node.

MERGE is more complex than you realize, and your queries are not doing what you think they're doing. You're creating additional nodes because even though there are :Product nodes with the productCode you're looking for, they don't have productLine properties, so a new node is created instead, leaving you with multiple :Product nodes that have the same productCode but having different sets of properties. You should be using MERGE only on the properties that uniquely identify the nodes you want, then use SET or ON CREATE SET or ON MERGE SET after your MERGE to set the additional properties.

More information on using MERGE here:

thank you Andrew, that seems to be the issue. However, i am not able to fix it. I tried using Coalesce but it doesnt work. As I am new to neo4j, can i ask you to help me with the syntax please ?
WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url
CALL apoc.load.jdbc(url,"orderinfo") YIELD row
MERGE (a:Order {orderNumber: COALESCE(row.orderNumber, "UNAVAILABLE")})
MERGE (b:Product { productCode: COALESCE(row.productCode, "UNAVAILABLE")})
MERGE (a)-[:PRODUCT3]->(b);

Tried ON CREATE too, but it seems to create UNAVAIL for all

WITH "jdbc:mysql://localhost:3306/test?user=root&password=Peculiarword1@" as url
CALL apoc.load.jdbc(url,"orderinfo") YIELD row
MERGE (a:Order {orderNumber: row.orderNumber})
MERGE (b:Product {productCode:row.productCode})
ON CREATE SET b.productLine='UNAVAIL'
MERGE (a)-[r1:PRODUCT15]->(b)
RETURN a,r1,b limit 50;

That just indicates the productCode is always null. Have you maybe misspelled it?