Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samitny/ce97e871499017b0297c to your computer and use it in GitHub Desktop.
Save samitny/ce97e871499017b0297c to your computer and use it in GitHub Desktop.
INSERT INTO campaigns_activities from activity where activity type is "subscriber" and action is "unsubscribe". (This is for a specific campaign ID which makes the join with "email_messages" pointless.)
INSERT INTO campaigns_activities (
SELECT
a.createdAt,
a.updatedAt,
a.id,
e.campaignId
FROM
activities a
LEFT JOIN
subscribers s ON (s.uuid = a.target)
LEFT JOIN
email_messages e ON (e.subscriberId = s.id AND e.`type` = 'bulk')
WHERE
a.type = 'subscriber'
AND
a.action = 'unsubscribe'
AND
e.campaignId = 4
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment