Answer the question
In order to leave comments, you need to log in
How to make a MASS UPDATE SQL query IN ONE ROW?
There is a problem. I am updating 30k+ rows in a loop. And it takes 40+ minutes.
That is, I run the following query in a loop:
UPDATE product
SET price = $product['price'],
price_retail = $product['price_retail']
WHERE upc = $product['supplier'] AND sku = $product['uniqCode']
Answer the question
In order to leave comments, you need to log in
1. You can do this in one query by using an intermediate table. First, load the data from the file into this table into the database, and then run update with one query. Do not forget to collect statistics on the table after loading data into it from a file.
2. Without an auxiliary table: you need an index on the fields sku, upc. But it won't be in one request.
Make a unique key for (upc, sku). Then
INSERT INTO `product` (`upc`, `sku`, `price`, `price_retail`)
VALUES (:upc1, :sku1, :price1, :price_retail1), ...,
(:upcN, :skuN, :priceN, :price_retailN)
ON DUPLICATE KEY UPDATE `price` = VALUES(`price`),
`price_retail` = VALUES(`price_retail`)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question