有两张表,table1,table2,其中都有字段a,现在想查询table1.a不存在于table2.a中的信息
我写了两个语句
select table1.* from table1,table2 where table1.a not in table2.a
和select table1.* from table1,table2 where table1.a != table2.a
可是执行后查询的数据只有一条数据且重复n边,不知道何种原因造成,我应该怎么写?
谢谢!

解决方案 »

  1.   

    select table1.* from table1 where table1.a not in (select a from table2 )
      

  2.   

    select t.* from table1 t where not exists(select 1 from table2 where a= t.a)
      

  3.   

    select * from table1 where not exists (select * from table1,table2 where table1.a=table2.a);
      

  4.   

    select a from table1
    minus
    select a from table2
      

  5.   

    这个简单,以前我也遇到了。。
    select t1.* from table1 t1 where not exists(select t2.* from table2 t2 where t2.a= t1.a)