有A表和B表,要查出A表在B表中不存在的记录,并将该记录插入B表(sql语句)

sql server2000和oracle查询语句都可以

你这个问题的前提是A和B是两个具有完全相同列结构的表。设她们都是只有两列,分别设为列1和列2.
下面是SQL SERVER的查询语言
insert into B
select A.列1,A.列2 from A where not exist select * from B where A.列1=B.列1 and A.列2=B.列2
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-14
insert into B select * from A where not exists (select 1 from B where A.id=B.id)
相似回答