mysql关于in/not in 查询替换

   在sql 中 采用not in 或者in的话 一般效率都很低并且很慢

一般都采用别的方式替换 一种是用 not in exits(单词忘怎么写了)

一种是用左连接查询 今天我用的是左连接查询解决我的问题

如下

select a.name ,a.userid from uts_group a left join
(select  DISTINCT serialNumber as s from logmessage  where serialNumber <> '' and operate='登录' and reserve3='uts/sso'
and operationTime>='2011-11-25 15:16:44' and operationTime<='2011-12-25 19:12:02') b
on a.userid=b.s   where  a.type='idsperson' and b.s is null

把not in(select * from table)看做是另一张表 如上面()中的

把 左边表和右边表的相关联的条件连接起来  最后加上 is null

有点啰嗦 心里明白 写不出来 有看不懂的 可以留言 

猜你喜欢

转载自sunyiqiang.iteye.com/blog/2105590
今日推荐