首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

三张表关联查询解决方案

2012-02-23 
三张表关联查询现在有三张表,1.2.3,都有身份证这个字段。想查出表3中的记录,既不在表1中,也不在表2中的数据

三张表关联查询
现在有三张表,1.2.3,都有身份证这个字段。
想查出表3中的记录,既不在表1中,也不在表2中的数据。
怎么写sql?请指教
谢谢!

[解决办法]

SQL code
 
select c.* from c where sfz not in (select sfz from a union select sfz from b) t


--or

select * from t a
where not exists(select 1 from t1 where sfz=a.sfz)
and  not exists(select 1 from t2 where sfz=a.sfz)

热点排行