SELECT huo_oy.hao,oy.hao
from huo_oy,oy
where oy.hao not in (huo_oy.hao)我是用2个表做的,在这个语句里,huo_oy.hao这个表是主表,在执行的时候,我发现,所有oy表里hao字段的内容,都要和主表里每个内容都对一遍主表huo_oy 副表oy
1            5
2            5
3            5
4            5
1            6
2            6
3            6
4            6  我想我只用NOT IN 来表示,然后我想,我用视图做个合并的表,分别把2表中的hao放在一个表里,然后我再和那两个表比,是不是更简单些呢,可是语句上我不太会写

解决方案 »

  1.   


    select hao
    from huo_oy
    where hao not in (select hao from oy)
      

  2.   

    SELECT huo_oy.hao,oy.hao
    from huo_oy,oy
    where oy.hao not in (selec hao from huo_oy)
      

  3.   


    select hao
    from oy
    where hao not in (select hao from huo_oy)
    --
    select a.hao
    from oy a join huo_oy b on a.hao = b.hao
    where b.hao is null
      

  4.   


    SELECT huo_oy.hao--,oy.hao这个没有意义
    from huo_oy LEFT JOIN oy ON huo_oy.hao=oy.hao
    WHERE oy.hao IS NULL
      

  5.   


    --单纯的可以这样
    select hao from huo_oy where hao not in (select hao from oy)
    --后面你说的就没看懂了