sql 数合并

来源:百度知道 编辑:UC知道 时间:2024/06/14 10:32:20
表1:
a 1
a 2
b 1
b 2
表2:
a 3
a 4
b 3
b 4
想把表2中的数放入表1.
得到
表1 数字不重复.
表2中的数据随但对应都可以.
表中有很多相同ID 一楼的答案不太实际

insert biao1 select * from biao2 where id not in (select id from biao1)

insert into 表1 (a1,a2,b1,b2) (select a3,a4,b3,b4,from 表2)

其两表的列的结构应是相同的

insert into 表1 (select a3,a4,b3,b4 from 表2 where not exists (select * from 表1.a1=表2.a3 and 这里写你的条件))