A
A
Alexander2017-05-04 19:03:48
PHP
Alexander, 2017-05-04 19:03:48

What is the best way to do an UPDATE query on the same column for 200 rows in MySQL?

Need to UPDATE 200, and in the future up to 1000 rows in MySQL. We update the value of only one column `Value`. We are looking for the column `ID` and update `Value`. What is the best way to write a query?
It is clear that doing the UPDATE command 200 times is not an option))
And how many maximum rows can be updated in one request so that everything does not die?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2017-05-05
@sanok_ps

In the end I solved it like this:

UPDATE table
    SET value = CASE id
        WHEN 1 THEN 'a'
        WHEN 2 THEN 'b'
        WHEN 3 THEN 'c'
    END
WHERE id IN (1,2,3)

P
Pavel Volintsev, 2017-05-04
@copist

Well, 200, well, 1000 - do it on parameterized cursors and don't worry.

V
V Sh., 2017-05-04
@JuniorNoobie

EXAMPLE

UPDATE tableB
INNER JOIN tableA ON tableB.name = tableA.name
SET tableB.value = tableA.value
WHERE tableA.name = 'Joe'

ORACLE uses the MERGE construct normally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question