Mysql update multiple update in one request


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/code-flow.club/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
4 views
Hello, I apologize in advance if this question seems childish.

You want to update 5 records in a single table in different rows.
Ie SET filed=1 where id=1, SET filed=2 where id=12, SET filed='0.5' where id=3...

Described as they could. I would be very grateful if will prompt for a path
by | 4 views

2 Answers

0 like 0 dislike
Your decision slow. It is more efficient to update 1 field in 1 regular query, no joins s.
Or use this option, it is much more effective in performance than Yours:
\r
UPDATE `table` SET `field` = CASE `id`
WHEN val1 THEN data1
WHEN val2 THEN data2
ELSE `field` END
\r
Just be sure to do not forget ELSE.
by
0 like 0 dislike
else can
\r
INSERT INTO `table` (id, field) VALUES (1, 1), (2, 12), (3, 0.5) ON DUPLICATE KEY UPDATE field = VALUES(field)
by

Related questions

0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
asked May 20, 2019 by Veneomin
0 like 0 dislike
7 answers
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
22,669 users