mysql 查询历史用户的疑问?

查看 32|回复 0
作者:Grocker   
表 t
[td]uid[/td]
[td]status[/td]
1
1
2
2
1
2
1
3
2
3
查询只存在 status=1 的用户,这两种写法有什么区别吗
SELECT * FROM t where `status` = 1 and uid not IN (
SELECT uid FROM  t as t1 WHERE `status` in (2,3) and t.uid = t1.uid
)
SELECT * FROM t where `status` = 1 and uid not IN (
SELECT uid FROM  t as t1 WHERE `status` in (2,3)
)
场景是查历史用户,即 status != 2,3 的,以上是简化的模型,两个字段都有索引
上面的多了一个子查询和外表的条件,在表数据量大的情况下性能谁更好,leader 说第一种查询效率会更高,因为它只在满足外表的条件下进行了过滤。或者有没有其他性能更好的写法?
您需要登录后才可以回帖 登录 | 立即注册

返回顶部