在MySQL上使用NOT IN的替代方法 [英] Alternative of NOT IN On MySQL

查看:1914
本文介绍了在MySQL上使用NOT IN的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询

SELECT DISTINCT phoneNum 
FROM `Transaction_Register` 
WHERE phoneNum NOT IN (SELECT phoneNum FROM `Subscription`) 
LIMIT 0 , 1000000

执行b/c花费太多时间Transaction_Register表具有数百万条记录 以上查询是否有其他选择,如果有的话,我将不胜感激.

It takes too much time to execute b/c Transaction_Register table has millions of records is there any alternative of above query I will be grateful to you guys if there is any.

推荐答案

一种替代方法是使用LEFT JOIN:

An alternative would be to use a LEFT JOIN:

select distinct t.phoneNum
from Transaction_Register t
left join Subscription s
  on t.phoneNum = s.phoneNum
where s.phoneNum is null
LIMIT 0 , 1000000;

请参见带有演示的SQL提琴

这篇关于在MySQL上使用NOT IN的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆