有两张表A 表B
表A的记录条数多 表B的记录条数少
如果要选出表A中不包含表B的记录 这个SQL怎么写啊select * from 表A where not in 表B吗?谢谢

解决方案 »

  1.   


    --测试
    select * from a
    left join b on a.id = b.id
    where b.id is null
      

  2.   

    二张表有关联的话,就可以这样
    select * from A where ID not in (select ID from B)
      

  3.   


    select * from 表A where id not in (select id from 表B) 
      

  4.   


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

  5.   

    先 select * from A inner join B
    然后delete all
    再看A表里的数据就行了,呵呵,此方法仅供娱乐!
      

  6.   

    drop table tab1
    drop table tab2
    go
    create table tab1(a int,b datetime)
    insert into tab1 select 12 ,     '2008-8-12'
    insert into tab1 select 12 ,     '2008-8-12' 
    insert into tab1 select 12  ,    '2008-8-14' 
    insert into tab1 select 15 ,     '2008-01-12' 
    insert into tab1 select 15 ,     '2008-2-14' 
    insert into tab1 select 17  ,    '2008-2-5' 
    create table tab2(a int,b datetime)
    insert into tab2 select 12 ,     '2008-8-12'
    insert into tab2 select 12 ,     '2008-8-12' select *
    from tab1
    where not exists(select 1 from tab2 where tab1.a=tab2.a and tab1.b=tab2.b)
      

  7.   

    select * from 表A where id not in (select id from 表B)
      

  8.   

    select * from A where id not in (select id from B)
      

  9.   


    select * from A where not exists (select id from B)
      

  10.   


    select * from A where id not in(select id from b)