我有以下表格:
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 r@gmail.com
2 2 r@gmail.com
3 3 j@gmail.com
I want to display all duplicates by email. Like this:
cont_id first_name email_address
1 Reeta r@gmail.com
2 Rohan r@gmail.com
这是我的查询:
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
);
查询需要很长时间才能执行大量记录。然而,内部查询工作得更快,但外部查询却不行。请帮忙。