表一   字段一    字段二    关健词
    12         50        10001
    14         14        10002
    13         14        10007
    15         10        10004
    17         17        10006表二   字段一    字段二    关健词
    12         50        10001
    14         13        10002
    13         14        10007
    15         10        10004
    17         NULL      10006求结果:
   字段一    字段二   字段一    字段二     关健词
    14         13      14         14       10002 
    17         NULL    17         17       10006求SQL语句    两表中对应的字段,值不相等的记录!

解决方案 »

  1.   

    select a.字段一, a.字段二, b.字段一, b.字段二, a.关健词
    from 表一 a join 表二 b on a.关健词 = b.关健词 and (a.字段一 <> b.字段一 and a.字段二 <> a.字段二)
      

  2.   

    写错了
    select a.字段一, a.字段二, b.字段一, b.字段二, a.关健词
    from 表一 a join 表二 b on a.关健词 = b.关健词 and (a.字段一 <> b.字段一 or a.字段二 <> a.字段二)
      

  3.   

    SET ANSI_NULLS OFFselect  
        a.字段一,
        a.字段二,
        b.字段一,
        b.字段二,
        a.关健词 
    from  
        表一 a,
        表二 b
    where
        a.关健词=b.关健词 and (a.字段一<>b.字段一 or a.字段二<>b.字段二)
      

  4.   

    SET ANSI_NULLS OFFselect  
        a.字段一,
        a.字段二,
        b.字段一,
        b.字段二,
        a.关健词 
    from  
        表一 a,
        表二 b
    where
        a.关健词=b.关健词 and (a.字段一<>b.字段一 or a.字段二<>b.字段二)SET ANSI_NULLS ON
      

  5.   

    如果某个关键字,一个表中有而另一个表中没有的,也要显示出来,就:select a.字段一, a.字段二, b.字段一, b.字段二, isnull(a.关健词, b.关健词) as 关健词
    from 表一 a full join 表二 b on a.关健词 = b.关健词 and (a.字段一 <> b.字段一 and a.字段二 <> a.字段二)
      

  6.   

    select b.字段一 ,b.字段二,a.* from 表一 a,表二 b where a.关健词=b.关健词 and a.checksum(*)<>b.checksum(*)
      

  7.   

    select a.字段一, a.字段二, b.字段一, b.字段二, a.关健词
    from 表一 a ,表二 b  where a.关健词 = b.关健词 and ((a.字段一 <> b.字段一 or a.字段二 <> a.字段二) or a.字段一 is null or b.字段一 is null or a.字段二 is null or b.字段二 is null)