两个数据表a和b,均包含字段“编号 名称 数量”,如何判断b表中存在的编号且在a表中不存在

解决方案 »

  1.   

    select b.*
    from b
      left join a
        on a.编号=b.编号
    where a.编号 is null
      

  2.   

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

  3.   

    select b.* from b where 编号 not in (select 编号 from a)
      

  4.   

    楼上的高手,如果b表中再加一个筛选条件"b.数量<5",sql语句该如何改
      

  5.   

    如果是2005, 就用EXCEPT, 否则, 只能用NOT EXISTS或者LEFT JOIN + IS NULL了.
    select 编号
    from b
    except
    select 编号
    from a