I have 2 tables, one called 'families' with fields 'id', 'email', and another one called 'progenitor' with fields 'id', 'family_id', 'email' (simplifying the rest of the fields).
I need to make a SELECT in which to return the email (if any) from the "families" table and each email from the "parent" table of that family, in case it is different from the family.
I have something like:
SELECT progenitor.email AS correo_progenitor,
familias.email AS correo_familia,
FROM familias
LEFT INNER JOIN progenitor
ON progenitor.id_familia = familias.id
WHERE progenitor.email IS NOT NULL
AND familias.email <> ''
AND progenitor.email <> familias.email
What I would need is a list of the non-repeated emails from both the families and parent table. With the code above only those in the parent table are shown. I do not know if it would be a matter of putting another SELECT inside but maybe there is a more effective formula of this type.
Thanks