有如下二个表
table1
uid name
1    李
2    王
3    刘table2
pkid uid
1     1
2     2
3     1查询: 如何查询 table2 中不包含的uid和name

解决方案 »

  1.   

    select * from table2 a where not exists(select 1 from table1 b where a.uid=b.uid)--2
    select * from table2 a where not in(select uid from table1 b where b.uid is not null)
      

  2.   

    select * from table2 a where not exists(select 1 from table1 b where a.uid=b.uid);
      

  3.   


    一般用not existsnot in 的改为select * from table2 a where a.uid not in(select uid from table1 b where b.uid is not null)
      

  4.   

    --落了
    select * from table2 a where a.uid not in(select uid from table1 b where b.uid is not null)