34,590
社区成员
发帖
与我相关
我的任务
分享
insert into b(fAID,fAname,)
select fid ,fName from a where fID not in(select fAID from b)
现在发现如下情况
情况一:
假设b表中 不存在fAID=1的记录 a表中存在fid=1 2条记录 执行上面sql 会向b表插入2条记录 而不是一条 为什么?
这个应该不会吧 再测试下
情况二:
假设b表中 存在fAID=1的记录 a表中存在fid=1 2条记录 执行上面sql 会向b表插入0条记录
请问我想实现 不重复插入数据 该怎么写?
insert into b select * from a where not exists(select 1 from b where faid=a.id)