Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created January 14, 2014 21:30
Show Gist options
  • Save tmountain/8426132 to your computer and use it in GitHub Desktop.
Save tmountain/8426132 to your computer and use it in GitHub Desktop.
UPDATE campaign,
(SELECT
c.id, IF(MAX(l.createTimestamp),
MAX(l.createTimestamp),
'0000-00-00') AS ts
FROM
campaign c
LEFT JOIN
lead l ON l.campaignID = c.id
GROUP BY c.id) timestamps
SET
campaign.lastActivity = timestamps.ts
WHERE
campaign.id = timestamps.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment