有a表,ID,name,b表,id,groupid,b表的id和a表的id是主外键关系,如何求出在b表中没有a表的数据。

解决方案 »

  1.   

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

  2.   

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

  3.   

    declare @a table(id int)
    declare @b table(id int)insert @a select 1 union all select 2 
    insert @b select 1 union all select 2 union all select 3
    select *
    from @b b
    where not exists(select id from @a where id = b.id)
    select *
    from @b b
    where id not in (select id from @a )
      

  4.   

    gahade(与君共勉) 写的select 1 from a where a.id=b.id这个1有什么作用,可以说一下吗