如何使用EXISTS而不是IN函数优化以下mysql查询?
Subscriber.first(:conditions => ["email IN(SELECT email from submissions WHERE url = ? AND confirmed != 0)", url], :order => "RANDOM()")
感谢您的帮助!
答案 0 :(得分:1)
基于存在的SQL语法
EXISTS (SELECT email from submissions x WHERE url = ? AND confirmed != 0 AND x.email = email)