I have a query
SELECT DISTINCT phoneNum
FROM `Transaction_Register`
WHERE phoneNum NOT IN (SELECT phoneNum FROM `Subscription`)
LIMIT 0 , 1000000
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.
解决方案
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;