I am trying to update multiple records (about a thousand of them) using this single statement (this is a process that will run every night). The statement below only includes 3 products for simplicity:
INSERT INTO productinventory
(ProductID, VendorID, CustomerPrice, ProductOverrides)
VALUES
(123, 3, 100.00, 'CustomerPrice'),
(124, 3, 100.00, 'CustomerPrice'),
(125, 3, 100.00, 'CustomerPrice')
ON DUPLICATE KEY UPDATE
CustomerPrice = VALUES(CustomerPrice),
ProductOverrides = CONCAT_WS(',', ProductOverrides, 'CustomerPrice')
;
Everything works fine except that the ProductOverrides
column gets the text 'CustomerPrice'
added to it every time this statement runs, so it ends up looking like this after it runs twice:
CustomerPrice,CustomerPrice
What I want the statement to do is to add 'CustomerPrice'
to the ProductOverrides
column, but only if that string does not already exist there. So that no matter how many times I run this statement, it only includes that string once. How do I modify this statement to achieve that?