偶遇到以下问题:TABLE1: (货架-货物对应表)
 货架编号     货物大类     货物编号    货物名称     
  001           1001       000001       货物1
  001           1001       000002       货物2
  002           1001       000001       货物1
  ............................................TABLE2 ( 货物编号表)
 货物大类     货物编号    货物名称  
 1001          000001       货物1
 1001          000002       货物2
 1001          .......      .....
 1002          000001       货物1 
 1002          000002       货物2
 ................................. 问题是这样的:
 如何编写SQL ,使没有在货架(001)中出现的货物编号列出来.
 偶的是这样的:
 select a.* 
 from table2 a, table1 b
 where b.货架编号 = '001' and (( a.货物大类 <> b.货物大类) and 
( a.货物编号 <> b.货物编号 ))结果: 没有达到期待结果而且出现很多重复的行

解决方案 »

  1.   

    使没有在货架(001)中出现的货物编号列出来:
    select * from table1 where 货架编号<>'001'
      

  2.   

    sorry,没有看仔细.
    使没有在货架(001)中出现的货物编号列出来:
    select * from talbe where 货物编号 not in
    (select distinct 货物编号 from table1 where 货架编号<>'001')
      

  3.   

    select * from talbe1 where 货物编号 not in
    (select distinct 货物编号 from table1 where 货架编号<>'001')
      

  4.   

    sorry. 需要再次 问题是这样的
     如何编写SQL ,使没有在货架(001)中出现的货物大类和货物编号列出来.
    (注: 每一样货物 由 货物大类和货物编号 组成的)要两个条件同时符合的
      

  5.   

    select * from table2 a where not exists (select 1 from table1 where 货架编号='001' and 货物大类=a.货物大类 and 货物编号=a.货物编号)
    上午好象做过这题!是同一个人吗?
      

  6.   

    select * from table2 a where not exists (select * from table1 where 货物大类=a.货物大类 and 货物编号=a.货物编号)
      

  7.   

    select * from table2 a where not exists (select 1 from table1 where 货架编号='001' and 货物大类=a.货物大类 and 货物编号=a.货物编号)