First time I am trying duplicate key to have insert and update in one query. What’s wrong with my query?
INSERT INTO tabletest(batchID, purchaseID)
VALUES (553155, 892) ON DUPLICATE KEY
UPDATE purchaseID = VALUES(purchaseID)
I’d like to insert or update if a batchID for a unique purchaseID exists. In the table purchaseID is UNIQUE.
If
purchaseIDis the column with theUNIQUEconstraint, then you should update onlybatchID: