--这个比in的效率应该要高.select *from Employee awhere not exists(select 1 from USERS where USERID=a.USERID)或者--在两个表的USERS的USERID上建立所以,应该会很快的.select a.*from Employee a left join USERS b
on a.USERID=b.USERID
where b.USERID is null

解决方案 »

  1.   

    SELECT * FROM USERS WHERE USERID NOT IN
    (SELECT USERID FROM EMPLOYER)
    =========================================记录算少的.先收集一下你两个表的统计信息.
    analyze table table_name compute statistics
    for table
    for all indexes
    for all indexed columns因为你的userid是作为主键.也就是unique索引.
    首先我提供以下几个写法的建议,你可以试试:1.select * from users a where not exists(select 1 from employer b where b.userid=a.userid);2.select * from users a where not exists(select 1 from employer b where b.userid=a.id);3.Select /*+ HASH_AJ */ *
    From Users
    Where Userid Not In (Select Userid From Employer Where Userid Is Not Null)方法很多.
    你自己可以通过查看执行计划来权衡.