表A和表B中,都有各自的记录,且二者有部分重复,怎么快速查出表A中除去与表B中重复的记录?表A:
ID,age,sex
1   15 男
2   17 男
3   16 女
4   17 男表B:
ID,age,sex
1   15 男
2   17 男
5   19 女
8   20 男
如何快速查出记录
3   16 女
4   17 男谢谢!

解决方案 »

  1.   

    SELECT A.* FROM A LEFT JOIN B ON A.ID=B.ID WHERE B.ID IS NULL
    ID上建立索引
      

  2.   

    select a.* from a where id not in(select id from b);select a.* from a where not exists(select 1 from a where a.id=b.id);
      

  3.   

    select *
    from A
    where not exists (select 1 from B where A.id=B.id and A.age=B.age and A.sex=B.sex)两个表的id上建立索引 如果没有的话
      

  4.   

    select * from A
    WHERE not exists(select 1 from B Where A.ID=B.ID AND A.age=b.age
    and A.SEX=B.SEX);
      

  5.   


    你们这样的效率低了...我上次去面试这样搞直接被pass了