Я подозреваю (но не знаю наверняка), и, надеюсь, кто-то, кто знает, подскакивает и исправляет меня, что объединение обновлений не создает декартово произведение, как это делает выбор.В качестве попытки доказательства
truncate table temp_table;
insert into temp_table values
( 'John' , 'mech' ),
( 'John' , 'abc' );
truncate table target_table;
insert into target_table values
('john', 'civil', 9 );
UPDATE target_table JOIN temp_table
ON temp_table.Name = target_table.Name
set target_table.type = (concat(target_table.Type,',',temp_table.Type));
select * from target_table;
+------+------------+------+
| Name | Type | LOC |
+------+------------+------+
| john | civil,mech | 9 |
+------+------------+------+
1 row in set (0.00 sec)
обратите внимание, что abc из temp_table игнорируется и мех выбирается чисто случайно.
, если мы изменим порядок в temp_table
truncate table temp_table;
insert into temp_table values
( 'John' , 'abc' ),
( 'John' , 'mech' );
truncate table target_table;
insert into target_table values
('john', 'civil', 9 );
UPDATE target_table JOIN temp_table
ON temp_table.Name = target_table.Name
set target_table.type = (concat(target_table.Type,',',temp_table.Type));
select * from target_table;
мы получаем
+------+-----------+------+
| Name | Type | LOC |
+------+-----------+------+
| john | civil,abc | 9 |
+------+-----------+------+
1 row in set (0.02 sec)
, где abc выбирается чисто случайно.
На мой взгляд, самый безопасный способ сделать это - строка за строкой, то есть курсор.