我必须从auto_increment
id字段的表中插入记录。
CREATE TEMPORARY TABLE tmptable SELECT *
FROM `wp_rg_lead_detail`
WHERE lead_id =59;
UPDATE tmptable SET lead_id =60 WHERE lead_id =59;
insert into `wp_rg_lead_detail` (`id`, `lead_id`, `form_id`, `field_number`, `value`)
select `id`, `lead_id`, `form_id`, `field_number`, `value`
from `tmptable`
WHERE lead_id =60;
键'PRIMARY'重复输入'1'
我需要在目标表中的auto_increment字段id
应该通过上面的查询递增。
答案 0 :(得分:0)
不要插入ID,并让列的autoincremenet属性处理它:
INSERT INTO `wp_rg_lead_detail`
(`lead_id`, `form_id`, `field_number`, `value`) -- No Id!
SELECT `lead_id`, `form_id`, `field_number`, `value`
FROM `tmptable`
WHERE `lead_id` = 60;