有两个表,有三个字段,,这两个表的结构是一样的,都是这三个字段。只是记录不同。
我现在想用SQL语句来把两个表中相同的记录筛选掉。然后生成一个新表。请问这个SQL怎么写????
谢谢。
select * into t3 from
(select * from t1 where not exists(select 1 from t2 where t1.单位名称=t2.单位名称 and t1.姓名=t2.姓名 and t1.金额=t2.金额)
union
select * from t2 where not exists(select 1 from t1 where t1.单位名称=t2.单位名称 and t1.姓名=t2.姓名 and t1.金额=t2.金额) a
select * into 新表 from (
select * from 表1 where not exists (select 1 from 表2 where 表1.单位名称=表2.单位名称 and 表1.姓名=表2.姓名 and 表1.金额=表2.金额)
union all
select * from 表2 where not exists (select 1 from 表1 where 表1.单位名称=表2.单位名称 and 表1.姓名=表2.姓名 and 表1.金额=表2.金额) ) tem
select * from 新表
select * into newtable from
(select * from table1 as A where not exists
(select * from table2 where 单位名称=A.单位名称 and 姓名=A.姓名 and 金额=A.金额)
union all
select * from table2 as B where not exists
(select * from table1 where 单位名称=B.单位名称 and 姓名=B.姓名 and 金额=B.金额)
) C