尝试此查询但没有正常工作,一些记录丢失, 我正在做的是,从驱动器文件夹中读取最近的文本文件 插入临时表。当我运行程序时,所有记录都来临了 表格正确,现在我想将它们发送到主表,如果记录是 已经出现在主要的他们不应该复制,怎么办??
insert into tblMain
select EnNo,DateTime from tblAllTempRecords
where DateTime not in(select DateTime from tblMain)
答案 0 :(得分:0)
您可以使用
除外INSERT INTO tblMain
SELECT EnNo, DATETIME
FROM tblAllTempRecords
EXCEPT
SELECT EnNo, DATETIME
FROM tblMain
答案 1 :(得分:0)
我怀疑你的子查询需要相关性:
insert into tblMain
select EnNo, DateTime
from tblAllTempRecords tr
where DateTime not in (select DateTime from tblMain m where tr.EnNo = m.EnNo)
还有其他方法可以写这个。例如,如果任一列可能具有负值,则not exists
优于not in
。
答案 2 :(得分:0)
我认为这就是你需要的
insert into tblMain
select EnNo,DateTime
from tblMain as t right JOIN tblAllTempRecords AS t1
ON t.EnNo = t1.EnNo
AND t.EnNo is null