我有以下表格: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