有两个表:document表和source表
document表里有一个字段叫docsource(文档来源,存储的是数字),
source表是一个对照表,有两列,一列是数字sourceid(这个sourceid对应document表里的docsource),一列是中文名称sourcename。
我想找document里有,但是source表里没有的行。这个sql怎么写呢?
想了半天,头大:(求高人解决~

解决方案 »

  1.   

    Select t.* from document t
    where not exists(
      Select * from source where sourceid=t.docsource)
      

  2.   

    select * from document a
         where a.docsource not in (select sourceid from source );
      

  3.   

    比较简单select d.* 
    from   document d
           source   s
    where  d.docsource = s.sourceid(+)
    and    s.sourceid IS NULL
      

  4.   

    用了1楼的方法,检索出来很多相同记录。是不是写成
    select distinct就行了?
      

  5.   


    Select document.* from document 
    where document.docsource not in(Select sourceid from source) 
      

  6.   

    --是的,过滤相同记录Select distinct t.* from document t 
    where not exists( 
      Select * from source where sourceid=t.docsource)