表1:
字段A, 字段B, 字段C表2:
字段A, 字段B, 字段C, 其它怎样获得表2中:字段A, 字段B, 字段C三个字段与表1中的三个字段不能同时相等的记录
如:
(表1)
字段A 字段B 字段C
1 2 3(表2)
字段A 字段B 字段C 其它
1 5 3 kk
2 2 7 ll
1 2 3 hh
1 3 3 yy要求结果:(表2)
字段A 字段B 字段C 其它
1 5 3 kk
2 2 7 ll
1 3 3 yy

解决方案 »

  1.   


    create table 表1(字段A int, 字段B int , 字段C int)create table 表2(字段A int , 字段B int , 字段C int , 其它 varchar(20))insert into 表1
    select 1,2,3select * from 表2
    insert into 表2
    select 1 ,5 ,3 ,'kk' 
    union select 
    2 ,2 ,7 ,'ll ' 
    insert into 表2 select 
    1 ,2 ,3 ,'hh '
     union select 
    1 ,3 ,3 ,'yy'select * 
    from 表2 a
    where not exists ( select * from 表1 b where a.字段A=b.字段A and a.字段B=b.字段B and a.字段C=b.字段C)
      

  2.   

    create table biao1
    (
     字段a char(1),
     字段b char(1),
     字段c char(1)
    )
    insert into biao1 select '1','2','3'
    create table biao2
    (
     字段a char(1),
     字段b char(1),
     字段c char(1),
     其他 char(2)
    )
    insert into biao2 select '1','5','3','kk'
    union all select '2','2','7','ll'
    union all select '1','2','3','hh'
    union all select '1','3','3','yy'
    select * from biao2 where not exists(select * from biao1 where biao1.字段a=biao2.字段a and biao1.字段b=biao2.字段b and biao1.字段c=biao2.字段c)
    drop table biao1,biao2