关于筛选重复记录的SQL语句???解决定送分

morningdew 2003-04-27 08:47:03
有两个表,有三个字段,(单位名称、姓名、金额),这两个表的结构是一样的,都是这三个字段。只是记录不同。

我现在想用SQL语句来把两个表中相同的记录筛选掉。然后生成一个新表(不包含两个表中都有的记录)。请问这个SQL怎么写????

谢谢。
...全文
94 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
愉快的登山者 2003-04-27
  • 打赏
  • 举报
回复
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
pengdali 2003-04-27
  • 打赏
  • 举报
回复
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 新表
happydreamer 2003-04-27
  • 打赏
  • 举报
回复




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
morningdew 2003-04-27
  • 打赏
  • 举报
回复
哦了。用了大力的方法。。送分。

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧