I started with this INSERT INTO ON DUPLICATE KEY UPDATE MySQL statement.
INSERT INTO Table1 ( field1, field2)
VALUES (1, 2)
ON DUPLICATE KEY UPDATE field1 = 1, field2 = 2
Then, I encountered an error " a foreign key constraint fails".
I realize I needed to add another WHERE clause condition to satisfy the foreign key constraint with an inner join.
I tried something like this;
INSERT INTO Table1 ( field1, field2)
Inner Join Table2
ON Table2.id = Table1.field_id
VALUES (1, 2)
ON DUPLICATE KEY UPDATE field1 = 1, field2 = 2
WHERE Table2.addr='123456'
I get syntax error. What is the proper way to write this MySQL statement?