读书人

sql查二张表出不相同部分

发布时间: 2012-09-29 10:30:01 作者: rapoo

sql查2张表出不相同部分
a表
name
a
b
c
b表
name1
aa
a
a1
b
c
c1

要查出
aa
a1
c1


[解决办法]

SQL code
select name1 from b表 except select name from a表
[解决办法]
探讨
LZ要查两张中不同的,而不是其中一个表的不同

SQL code


select name from a except select name1 from b
union
select name1 from b except select name from a

[解决办法]
SQL code
select distinct a.search from a full join b on checksum(a.search)=checksum(b.Name)where a.id is null or b.id is NULL
[解决办法]
没有什么好的方法了?
[解决办法]
SQL code
select name from a where not exist(select * from b where name1=a.name)unionselect name1 from b where not exist (select * from a where name=b.name1) 

读书人网 >SQL Server

热点推荐