表1
RID(自动增长) 
lType (int)
表2RID(外键引用表1 RID)
Result(boolean)要求查询出表1中,lType = 7 且 表2 没有的数据

解决方案 »

  1.   

    select * from 表1 where itpe=7 and rid not in(select rid from 表2)
      

  2.   

    传说这样查询速度会快点
    select * from 表1 where itpe=7 and not exists(select 1 from 表2 where 表1.rid=表2.rid)
      

  3.   

    SELECT *
    FROM 表1 a
    WHERE ITYPE= 7 AND  RID NOT IN (SELECT RID FROM 表2 )
      

  4.   


    select * from [表1] where itpe=7 and rid not in (select [表1].rid from [表1] inner join [表2] on [表1].rid = [表2].rid)
      

  5.   

    select 表1.* from 表1
    left join 表2 on 表1.RID=表2.RID
    where 表2.RID is null
      

  6.   

    快不快要看执行计划的,按照“建议”,用exists比not exists更快