Answers.Body: <p>Achieved this via SQL</p>
  <p>Step 1. Identify contacts who the log_civicrm_group_contact table shows were added to the group (and who are not now in Trash, since we can add Trashed contacts to a Group) with a query that includes the value of the new group they will be added to (in this case 893) and filters for the Group that was deleted (764)</p>
  <blockquote>
  <p>select 893, contact_id, log_civicrm_group_contact.status
  FROM log_civicrm_group_contact
  LEFT JOIN civicrm_contact cc ON cc.id = log_civicrm_group_contact.contact_id
  WHERE group_id = 764
  AND status = &quot;Added&quot;
  AND log_action = &quot;Insert&quot;
  AND cc.is_deleted = 0
  ORDER BY contact_id;</p>
  </blockquote>
  <p>Then we grab the result as an SQL insert as follows</p>
  <blockquote>
  <p>INSERT INTO <code>civicrm_group_contact</code> (<code>group_id</code>, <code>contact_id</code>, <code>status</code>)
  VALUES</p>
  </blockquote>
  <p>with rows like</p>
  <blockquote>
  <p>(893, 76639, 'Added')</p>
  </blockquote>
  <p>Note we ORDERED by contact_id as we had too bit a sql insert so it got cut off, and by ordering by id we could rerun the insert scrip for those which got dropped from previous run.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-21T02:31:27.683Z
Answers.LastActivityDate: 2023-01-21T02:31:27.683Z
Answers.UserDisplayName: petednz - fuzion
Body: <p>Scenario is - contacts had been added to a Group (in this case for subsequent deletion) but a user then incorrectly deleted the Group, rather than the contacts in the Group.</p>
  
Tags: <groups>
Title: How can I restore the data from a deleted Group
ThreadText: # How can I restore the data from a deleted Group
  
  (Asked by: username_0 on 2023-01-21)
  
  Scenario is - contacts had been added to a Group (in this case for subsequent deletion) but a user then incorrectly deleted the Group, rather than the contacts in the Group.
  
  **Tags:** groups
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-01-21. Score: 1
  
  Achieved this via SQL
  
  Step 1. Identify contacts who the log\_civicrm\_group\_contact table shows were added to the group (and who are not now in Trash, since we can add Trashed contacts to a Group) with a query that includes the value of the new group they will be added to (in this case 893) and filters for the Group that was deleted (764)
  
  > select 893, contact\_id, log\_civicrm\_group\_contact.status
  > FROM log\_civicrm\_group\_contact
  > LEFT JOIN civicrm\_contact cc ON cc.id = log\_civicrm\_group\_contact.contact\_id
  > WHERE group\_id = 764
  > AND status = "Added"
  > AND log\_action = "Insert"
  > AND cc.is\_deleted = 0
  > ORDER BY contact\_id;
  
  Then we grab the result as an SQL insert as follows
  
  > INSERT INTO `civicrm_group_contact` (`group_id`, `contact_id`, `status`)
  > VALUES
  
  with rows like
  
  > (893, 76639, 'Added')
  
  Note we ORDERED by contact\_id as we had too bit a sql insert so it got cut off, and by ordering by id we could rerun the insert scrip for those which got dropped from previous run.
  
  
  ---
  
  