两个表的结构完全相同,如何找出的差异记录。
A表
N M
aa 131
bb 311
cc 3124
aa 581
.
.
.A表
N M
aa 213
bb 311
cc 3124
aa 581
dd 100
.
.
.如何找出两表中不相同的记录。
A表
N M
aa 131
bb 311
cc 3124
aa 581
.
.
.A表
N M
aa 213
bb 311
cc 3124
aa 581
dd 100
.
.
.如何找出两表中不相同的记录。
解决方案 »
- 问个小问题
- 还原数据库时的问题
- SQLServer中如何只取得datetime类型的日期部分?
- SQL2000删除重复记录
- 上亿条记录,表的设计问题,请教!!!!!
- ###### 多表结合查询 返回 结果集 &&&&&&
- 在一台服务器上建了2个不同的数据库,怎么从一个库中去访问另一个库中的表?
- 为什么连接SQL总是提示用户 'XX' 登录失败。原因: 未与信任 SQL Server 连接相关联
- 求Ms Sql高手解答。。。。。。。。。???急
- 我的某个列的值为空,但是,where 列名='' 不匹配它。何故?
- 如何在同一台服务器上复制数据库?
- 回家前提个问题 关于 sql中两行合并的问题 希望大家能给出正确答案 谢谢啦
where not exists(select 1 from b where a.n=b.n and a.m=b.m)
union
select * from b
where not exists(select 1 from a where a.n=b.n and a.m=b.m)
我加分啊。
select * from a ,b where a.n=b.n and a.m<>b.m
where A.M <> B.M
where exists(select 1 from b where a.n=b.n and a.m<>b.m)
union all
select * from b
where exists(select 1 from a where a.n=b.n and a.m<>b.m)
minus
select * from b
union all
select * from b
minus
select * from a
select * from (select * from a except select * from b)t
union all
select * from (select * from b except select * from a)t
select * from a where checksum (*) not in(select checksum (*) from b)
union all
select * from b where checksum (*) not in(select checksum (*) from a)
set nocount on
if object_id('tempdb.dbo.#a') is not null drop table #a
if object_id('tempdb.dbo.#b') is not null drop table #b---------------例子数据 begin---------------
create table #a (N varchar,M int)
insert into #a
select 'a',131 union all
select 'b',311 union all
select 'c',3124 union all
select 'a',581create table #b (N varchar,M int)
insert into #b
select 'a',213 union all
select 'b',311 union all
select 'c',3124 union all
select 'a',581 union all
select 'd',100
---------------例子数据 end------------------------------源程序 begin--------------
select * from #a
select * from #b
select * from #a a where not exists (select 1 from #b where a.N=N and a.M=M) union
select * from #b b where not exists (select 1 from #a where N=b.N and M=b.M)
drop table #a,#b
set nocount off
---------------源程序 end---------------/*****************************
N M
1 a 131
2 a 213
3 b 100
*****************************/
两个问题:
1.不知道怎么输入aa,只好用a代替,晕倒。
2.checksum(*)可以解决问题。
3.程序太臃肿了。
select * from #a a where not exists (select 1 from #b where a.N=N and a.M=M) union
select * from #b b where not exists (select 1 from #a where N=b.N and M=b.M) 默默努力中