同上:(id2为筛选条件)
  T1
     id1   id2
       1    13
       2    3
       3    4  T2
     id1   id2
       1    13
       2     5
       3     4
查询后得到:
      id1    id2
       2      3

解决方案 »

  1.   

    select t1.*  from t1,t2 where t1.id1=t2.id1 and t1.id2<>t2.id2
      

  2.   

    select * from t1 x where not exists (select * from t2 y where y.id1 = x.id1 and y.id2 = x.id2)
      

  3.   

    declare @t1 table(id1 int,id2 int)
    insert @t1 values(1,13)
    insert @t1 values(2,3)
    insert @t1 values(3,4)declare @t2 table(id1 int,id2 int)
    insert @t2 values(1,13)
    insert @t2 values(2,5)
    insert @t2 values(3,4)select t1.*  from @t1 t1,@t2 t2 where t1.id1=t2.id1 and t1.id2<>t2.id2
      

  4.   

    select * from t1
    where exists(select id1 from t2 where t2.id1=t1.id1 and t2.id2<>t1.td2)

    select * from t1
    where not exists(select id1 from t2 where t2.id1=t1.id1 and t2.id2=t1.td2)
      

  5.   

    sorry,我说错了,出来的结果要T1 和T2不重复的两个表中的数据,像上面的例子:
           结果应该是:
                id1   id2
                  2    3
                  2    5
      

  6.   

    select * from t1 union select * from t2系统会自动过滤掉完全相同的记录,要是想不过滤,就用union all 代替 union
      

  7.   

    select * from t1
    where id not in (select id1 from t2 where t2.id1=t1.id1 and t2.id2<>t1.td2)
      

  8.   

    dave_c() 的方法应该不行
    出来的结果会是: 
     1    13
     2     3
     2     5
     3     4
      

  9.   

    select * from t1 x where not exists (select * from t2 y where y.id1 = x.id1 and y.id2 = x.id2)
    union
    select * from t2 x where not exists (select * from t1 y where y.id1 = x.id1 and y.id2 = x.id2)
      

  10.   

    declare @t1 table(id1 int,id2 int)
    insert @t1 values(1,13)
    insert @t1 values(2,3)
    insert @t1 values(3,4)declare @t2 table(id1 int,id2 int)
    insert @t2 values(1,13)
    insert @t2 values(2,5)
    insert @t2 values(3,4)select x.* from @t1 x where exists (select 1 from @t2 y where (x.id1 = y.id1 and x.id2<>y.id2) or (x.id1 <> y.id1 and x.id2=y.id2))
    union all
    select y.* from @t2 y where exists (select 1 from @t1 x where (x.id1 = y.id1 and x.id2<>y.id2) or (x.id1 <> y.id1 and x.id2=y.id2))