问题是这样的:
  
有两张表:table 1 的结构:
  
  id1  id2  1     1
  1     2
  3     4
  6     9table 2的结构:
  id1    id2
   1     1
   1     2
   3     4
   7     11
就是希望实现 oracle的 minus的效果:select * from table1
minus
select * from table2;
 
id1   id2
6      9mysql 要得到这种结果要怎么写才可以呢?

解决方案 »

  1.   

    select * from table1 t1
    where not exists (select 1 from table2 t2 where t1.id1 = t2.id1 and t1.id2 = t2.id2)如果id1本身就都是主键的话,可以
    select * from table1 t1
    where not exists (select 1 from table2 t2 where t1.id1 = t2.id1)
      

  2.   

    select *
    from tb1 A
    where not exists (select 1 from tb2 id1=A.id1 and id2=A.id2)
      

  3.   

    select * from table1 left join table2 on table1.id1=table2.id1 and table1=id2=table2.id2 where table2.id1 is null
      

  4.   

    as long as id1 is not nullable