Created
November 4, 2016 21:06
-
-
Save iiwo/89c0790b271c82535a915f0c7bb0cfb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT COUNT(*) | |
FROM "users" | |
LEFT OUTER JOIN blacklisted_emails b_e ON LOWER(b_e.email) = LOWER(users.email) | |
LEFT OUTER JOIN | |
(SELECT "campaign_emails".* | |
FROM "campaign_emails" | |
INNER JOIN "campaign_blasts" ON "campaign_blasts"."id" = "campaign_emails"."campaign_blast_id" | |
INNER JOIN "email_campaigns" ON "email_campaigns"."id" = "campaign_blasts"."email_campaign_id" | |
WHERE (email_campaigns.id = NULL)) c_e ON c_e.user_id = users.id | |
WHERE (b_e.email IS NULL) | |
AND (c_e.id IS NULL) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment