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

如何从一个表中分离出包含在表二中的相同字段内容的数据集
大家好

        我有两个表   T1和T2,   T1   和   T2   中都有相同的字段,   F1   ,  

        如何用   Sql语句产生结果集   :  
 
              1\   select   F1   from   T1   where   F1   不包含在   T2中  

              2\   select   F1   from   T1   where   F1   包含在   T2中  

谢谢


------解决方案--------------------
?

1
select * from t1 where f1 not in(select f1 from t2)
or
select * from t1 where not exists (select 1 from t2 where t2.f1=t1.f1)

2
select * from t1 where f1 in(select f1 from t2)
or
select * from t1 where exists (select 1 from t2 where t2.f1=t1.f1)