表1
A列 B列
1   10
1   20
1   30
2   30
2   20
2   10表2
A列 B列
1   10
2   30
2   10根据表1和表2 找出表1的数值不包括表2的数值结果
A列 B列
1   20
1   30
2   20

解决方案 »

  1.   

    select tb1.* from tb1 where not exists (select 1 from tb2 where tb2.a = tb1.a and tb2.b = tb1.b)
      

  2.   

    create table tb1(A int, B int)
    insert into tb1 values(1 , 10 )
    insert into tb1 values(1 , 20 )
    insert into tb1 values(1 , 30 )
    insert into tb1 values(2 , 30 )
    insert into tb1 values(2 , 20 )
    insert into tb1 values(2 , 10 )
    create table tb2(A int, B int)
    insert into tb2 values(1 , 10 )
    insert into tb2 values(2 , 30 )
    insert into tb2 values(2 , 10 )select tb1.* from tb1 where not exists (select 1 from tb2 where tb2.a = tb1.a and tb2.b = tb1.b)drop table tb1 , tb2/*
    A           B           
    ----------- ----------- 
    1           20
    1           30
    2           20(所影响的行数为 3 行)
    */
      

  3.   

    select 表1.* from 表1,表2
    where  表1.A列 <>表2.A列 
    and  表1.B列<>表2.B列