有一张表father   
  字段1   
   aa
   bb
   cc
   ...sonid   字段1   字段2
1    aa       aa11
2    aa       aa22
3    cc       cc11 
..    ...       ... 我想查询子类中没有,父类含有子类为0的父类 字段1 怎么查询啊????
同志们帮我解决问题的时候顺便介绍些sql语句书我看看
我sql功底太差了

解决方案 »

  1.   

    select * from father where not exists (select 1 from son where 字段1=father.字段1)
    --
    这样?
      

  2.   

    select * from father where not exists (select 1 from son where 字段1=father.字段1)
    -- or
    select * from father left join son on father.字段1=son.字段1
    where son.字段1 is null
      

  3.   

    -- or
    select * from father where 字段1 not in (select 字段1 from son)
      

  4.   


    --父类含有的但子类中无的记录
    select * from father where 字段1 not in (select 字段1 from son)
    --多看看MSDN.有问题就来CSDN....
      

  5.   

    select 字段1 from father where 字段1 not in(select 字段1 from son)
      

  6.   

    select * from father where 字段1 not in (select distinct 字段1 from son)
    --或者
    select * from father left join son on father.字段1=son.字段1
    where son.字段1 is null