UPDATE `table` SET `rubriq` = '77' WHERE `rubriq` = '61';
UPDATE `table` SET `rubriq` = '77' WHERE `rubriq` = '62';
UPDATE `table` SET `rubriq` = '77' WHERE `rubriq` = '63';
在表格中我有两列abonne和rubriq. Abonne是主键,两个是索引.
如果在我的数据库中我有例如:
abonne | rubriq
84 | 61
84 | 62
84 | 63
当我运行我的3个查询时,第一个没有问题但是对于第二个,我有一个错误:#1062 – 重复条目’84 -77’为密钥1
谢谢 !
最佳答案
您必须手动删除会导致冲突的记录:
原文链接:https://www.f2er.com/mysql/432824.htmlUPDATE `table` SET rubriq = 77 WHERE rubriq = 61;
DELETE t62
FROM `table` t77
JOIN `table` t62 USING (abonne)
WHERE t77.rubriq = 77
AND t62.rubriq = 62;
UPDATE `table` SET rubriq = 77 WHERE rubriq = 62;
DELETE t63
FROM `table` t77
JOIN `table` t63 USING (abonne)
WHERE t77.rubriq = 77
AND t63.rubriq = 63;
UPDATE `table` SET rubriq = 77 WHERE rubriq = 63;