请问一SQL语句:
请问一SQL语句:
有表T1,T2
T1有如下2列
C1 C2
PA 1
PA 2
PA 3
PB 1
PB 2
PB 4
T2有如下3列
C1 C2 C3
PA 1
PA 3
PB 1
PB 2
PB 3
现在要将表T1中不在表T2中的记录插入表T2中,请问SQL语句怎么写?谢谢!
------解决方案--------------------INSERT INTO T2 ( C1, C2 )
SELECT A.C1, A.C2
FROM T1 as A
left join T2 as B on A.C1=B.C1 and A.C2=B.C2
where isnull(B.C1) or isnull(B.C2)
--或者
INSERT INTO T2 ( C1, C2 )
SELECT C1, C2
FROM T1
where C1 & C2 NOT in (select C1 & C2 from T2)