2个表
比如
表1,主键a,b c,d
表2,主键c,d,e,f查询表1有的,在表2没有的(也就是a,b)

解决方案 »

  1.   

    select * from table1 where d not in (select d from table2);
      

  2.   

    2楼大大答的好像与楼主的意思不同哦。楼主的意思是否说 表1有五个属性(列):主键 ,a,b,c,d   表2的属性(列)为c,d,e,f,你想要的是表一与表二不同的列 a,b如果是的话,数据库好像做不到这样的识别,因为数据库只认为表1和表2的c,d是不同的两个东西,只是同名而已,你要的那个应该是实现不了的。
      

  3.   


    create table tt1 (
    a int not null,
    b int not null,
    c int not null,
    d int not null,
    primary key (a,b,c,d)
    );
    create table tt2(
    c int not null,
    d int not null,
    e int not null,
    f int not null,
    primary key (c,d,e,f)
    );create temporary table tmp1 select * from information_schema.statistics where table_schema = 'test' and table_name = 'tt1';
    create temporary table tmp2 select * from information_schema.statistics where table_schema = 'test' and table_name = 'tt2';select tmp1.column_name as diff from tmp1 left join tmp2  using(column_name) where tmp2.column_name is null;
    结果:
    query result(2 records)
    diff