我有以下表格:MySQL查询需要长时间
Table 1 : Contacts
Fields : id first_name
Values :
1 Reeta
2 Rohan
3 John
Table 2 : email (it contains contact_id of contacts table)
Fields : id contact_id email_address
Values :
1 1 [email protected]
2 2 [email protected]
3 3 [email protected]
我想显示通过电子邮件所有重复。就像这样:
cont_id first_name email_address
1 Reeta [email protected]
2 Rohan [email protected]
这里是我的查询:
select contact_id
from contacts
where email_address IN (
SELECT S.email_address
FROM contacts R
INNER JOIN email
ON R.id = S.contact_id
Group By email_address
Having Count(S.id) > 1
);
查询需要很长的时间与大量的记录来执行。然而,内部查询的工作更快,但不是外部查询。请帮忙。
有多少条记录需要多长时间? – Jasper
你创建了哪些索引? id,contact_id,email_address需要索引 – mseifert