table 1
id  value
1    111
1    222
1    444 
3    333
3    444table 2
id  value
1    222
1    444
2    111 
3    444得到
table 2
id  value
1    111
3    333
就是找到按照每个ID,Value值在表1中有而在表2种没有的门所有记录

解决方案 »

  1.   

    select * from table1 a
      where not exists(select * from table2 where id=a.id and value=a.value)
      

  2.   

    select * from table1 a
      where not exists(select 1 from table2 where id=a.id and value=a.value)
      

  3.   

    select * from table1 where value not in (select value from table2)
      

  4.   

    select * from table1
    where value not in (select value from table2 where table1.id = table2.id)
      

  5.   

    如果是这样呢,怎么做
    table 1
    AA id  value
    1   1    111
    1   1    222
    1   1    444 
    1   3    333
    1   3    444
    2   1    222
    2   1    444
    2   2    111 
    2   3    444
    得到
    table 2
    AA id  value
    1   1    111
    1   3    333
    就是找到按照每个ID,Value值在表1中有而在表2种没有的门所有记录