A NOT IN()
подзаявката може да се използва тук, тъй като MySQL не поддържа MINUS
.
SELECT
cand_email
FROM tbl_cand_data
WHERE can_email NOT IN (SELECT un_email FROM tbl_unsubscribe)
Може да се направи и с LEFT JOIN
, търсейки NULL в un_email
колона:
SELECT cand_email
FROM
tbl_cand_data
LEFT JOIN tbl_unsubscribe ON tbl_cand_data.can_email = tbl_unsubscribe.un_email
WHERE tbl_unsubscribe.un_email IS NULL
За да ги изключите от група UNION
операции, обвийте UNION
група в ()
като подзаявка:
SELECT email FROM (
SELECT cand_email AS email FROM tbl_cand_data
UNION
SELECT emp_email AS email FROM tbl_emp_data
UNION
SELECT email FROM AS email tbl_uptade_list
UNION
SELECT feed_email AS email FROM tbl_feedback
UNION
SELECT admin_email AS email FROM tbl_admin_emails
) email_list
WHERE email NOT IN (SELECT un_email FROM tbl_unsubscribe)