I am searching for an easy solution. I wanna Update 800 rows of data. There is no unique ID so the ON DUPLICATE KEY Update is not possible.
I only show 3 rows of data, but there are over 800. So i wanna update the quantity of a product list directly in the database.
I tried like this, but that did not work and i don’t know why. My code is not working.
UPDATE `xt_products` SET `products_quantity` = [Value-2] WHERE `products_model`= [Value-1]
('2','0'),
('3','1'),
('32','25'),
value-2 means the second input of the data-row (0,1,25)
value-1 means the first input of the data-row (2,3,32)
When i do only one row it works:
UPDATE `xt_products` SET `products_quantity` = "25" WHERE `products_model`= "32"
The Column products_model:
products_model varchar(255) utf8mb4_general_ci NULL
But how i get the data into the command? value-1 and value-2 ?
I tried different ways for a solution. But i didn’t find one.
I wanna update directly in the sql-command field at the database.
2
Answers
Seems not so easy to find a solution. So i did it my way. It is easier to change the file with the right program. I switched quality and quantity in the sequence (really easy from the output program). Then i do a prefix in each line
i replaced the ; between the numbers with
and the suffix in each line ,
Result:
Around 800 rows of simple Update code. And it works. Took me 1min to insert prefix, replace and suffix.
I know, it is not the nice way, but simple and effective for me.
Based on the example you gave, you can do:
Short explanation:
The query:
returns:
xt_products
More info:
NOTE:
products_quantity
, this fields seems to be numeric. When using numeric data in MySQL, you should not use quotes around the value, so you should doROW('2',0)
, and notROW('2','0')
product_model
could also be like "T23WX"", you should not (NEVER) use over simplified example data like'1'
, or'2'
. Just use the REAL names there, or if that is not possible use flower names, or planet names, or any other anonymus list.