We run several CiviCRM instances with our Drupal sites. One issue we ran into recently concerned contacts who unsubscribe from one group which was a subset of a larger group of contacts (of which they also belonged). When they would unsubscribe from one, they would still be subscribed to the other and thus were still receiving the newsletter. Aside from the fact that the group/newsletter setup was a bit un-ideal, we had to address the issue and manually unsubscribe the contacts from the other group. Here's how we did it:
UPDATE civicrm_group_contact SET status = 'Removed' WHERE group_id = 3 AND contact_id IN (SELECT * FROM (SELECT contact_id FROM civicrm_group_contact WHERE group_id = 2 AND status = 'Removed') AS civicrm_group_contact_temp);
You'll see one odd thing about the query above -- a sub, sub query:
... AND contact_id IN (SELECT * FROM (SELECT ...
This creates a temp table allowing us to simultaneously run SELECT and UPDATE commands on the same table at the same time. See MySQL's Subquery Restrictions for more information.
Post new comment