从多个表插入会产生重复的输入错误

时间:2017-11-27 18:18:06

标签: mysql

我在mysql中有两个名为ab的表格。它们都有一个唯一的列id。现在,我想通过插入表abcid中的记录来创建一个a作为自动增量列的表b

Table a

1 sam
2 ram
3 tim


table b 

1 tom
2 sun
3 jim

期望的结果

table abc

1 sam
2 ram
3 tim
4 tom
5 sun
6 jim

我试过以下

insert into table abc select * from a

此声明成功运行

insert into table abc select * from b`

此声明无法说明主要

的重复条目

如何实现我想要的结果

1 个答案:

答案 0 :(得分:1)

AUTO_INCREMENT表中的abc列创建自己的值。不要从其他表格中选择并插入id列。

insert into table abc(names) select names from a order by id;
insert into table abc(names) select names from b order by id;
相关问题