日期:2014-05-18  浏览次数:20516 次

怎么从两个表中找出主键不同的记录,散分,在线
我现在有两个表,表结构不同,有一个字段(用户)相同

现在我怎么找出其中不相同的记录,我指的不相同是指多的记录或者少的记录!

========================================================
比如:
A   表
name                     tel                   addreess
--------------------------------------
张三               1111111           222222222
李四                   1111111           222222222


B   表
name                     tel                   addreess
--------------------------------------
张三               1111111           222222222

==================================================

我怎么找出A表中多的李四

不知道我的问题描叙清楚了没有,有哪位知道,谢谢了!

------解决方案--------------------
select * from A
where not exists(select 1 from B where A.name=B.name)
------解决方案--------------------
或者
select a.*
from a left outer join b on a.name=b.name
where b.name is null
------解决方案--------------------
select * into othertable from A
where not exists(select 1 from B where A.name=B.name)