0
I want to get the contact table records that have the same email. Only the email is a field of the email table because this way the contact can have several emails (One To Many).
// Tabela contato
id name
1 Alladin
2 Dumbo
3 Pluto
// Tabela email
id email contact_id
1 dumbo@disney.com 2
2 alladin@disney.com 1
3 dumbo@disney.com 3
I need to get the two records that have the same email and that are different contacts, for example:
id name email
2 Dumbo dumbo@disney.com
3 Pluto dumbo@disney.com
I tried the following query but unsuccessfully:
SELECT c.id, c.name, e.email FROM contato c
INNER JOIN email e ON e.contact_id = c.id
WHERE e.email IN (SELECT e2.email FROM email e2 GROUP BY e2.email HAVING COUNT(*) > 1);
Such an output (https://i.imgur.com/Poefyfh.png) would solve?
– Woss
@Andersoncarloswoss, would solve yes.
– Victor Carnaval