A 表
id
1
2
3 b表
id
2
3
我想用not exists 查询出A表中哪些数据不在B表,也就是1

解决方案 »

  1.   

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

  2.   


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

  3.   


    少 where  居然写错了!!!  
      

  4.   

    create table A(id int)
    insert into A select 1 union all select 2 union all select 3
    create table B(id int)
    insert into B select 2 union all select 3--#2
    select * from A
    where not exists(select top 1 1 from B where B.id = A.id)
    --#2
    select * from A
    except
    select * from B
      

  5.   

    --#3
    select A.id from A
    outer apply
    (select top(1) * from B where B.id = A.id) b
    where B.id is null