表A, a.id  表B,b.id
其中a.id与b.id字段值部分相等.
现求, a.id=b.id 不相等a表中的值(意思a表中字段a.id在B表中字段b.id,中不相等的那些值,(不显示a.id=b.id的所有值,而显示a.id!=b.id的所有值))
求SQL语法!

解决方案 »

  1.   

    select a.*
       from a
    where not exists(select 1
       from b
        where a.id=b.id)
      

  2.   

    select a.*
       from a
       where a.id not in  (select id
                                from b)
      

  3.   

    select * from a where a.id not in(select b.id from b);
      

  4.   

    select a.* from a
    where not exists (select 1 from b where a.id=b.id);select a.* from a where a.id not in(select b.id from b);兩個都行,如果B表中資料較多,用exists.
      

  5.   

    还有一种写法select a.* from A left outer join B on a.id=b.id where b.id is null