Answers.Body: <p>Its generally a contact with lower ID that's preserved. </p>
  
  <p>For aggressive merges, fields in conflict are retained from that of higher contact ID. In other words, for fields in conflict, value from higher ID overwrites on that of lower ID.</p>
  
  <p>Preserving of contact, is due to the way dedupe queries are written. </p>
  
  <p>A. Example:
  <code>INSERT INTO dedupe (id1, id2, weight) SELECT t1.id id1, t2.id id2, 10 weight FROM civicrm_contact t1 JOIN civicrm_contact t2 USING (first_name) WHERE t1.id &lt; t2.id AND t1.first_name IS NOT NULL GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight);
  </code></p>
  
  <p>B. Here is the code and comment that makes it clear - <a href="https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L636">https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L636</a></p>
  
  <p>However with CiviCRM v4.5 and above, you can decide the biasing (which contact to preserve) using merge hook - <a href="https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L632">https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L632</a></p>
  
  <p>Here is an implementation example where a contact with maximum number of contributions is preserved - <a href="https://github.com/civicrm/civicrm-drupal/blob/7.x-4.5/civitest.module.sample#L1279">https://github.com/civicrm/civicrm-drupal/blob/7.x-4.5/civitest.module.sample#L1279</a></p>
  
  <p>Same hook could also be used for deciding which value to preserve by playing with $conflicts variable. Here is an example that we did for one of our client - <a href="https://github.com/veda-consulting/uk.co.vedaconsulting.module.dedupe/blob/master/dedupe.php#L218">https://github.com/veda-consulting/uk.co.vedaconsulting.module.dedupe/blob/master/dedupe.php#L218</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-10T18:05:11.403Z
Answers.Text: I've tested this and found a different result. Using Civi 5.45.3. Fields in conflict are retained from that of the lower contact ID. Tested email, phone, address.
Answers.UserDisplayName: Andy Burns
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-21T11:46:13.290Z
Answers.LastActivityDate: 2015-05-21T12:00:17.500Z
Answers.LastEditDate: 2015-05-21T12:00:17.500Z
Answers.UserDisplayName: Deepak Srivastava
Body: <p>We are investigating the 'Process batch merge' scheduled job in CiviCRM, to automatically batch merge duplicate contacts. This calls api.job.processBatchMerge which seems to take the rule to use as a parameter and also a mode, 'safe' or 'aggressive'.</p>
  
  <p>'Safe' mode skips the merge if there are conflicts (which is probably best for an automated process!)</p>
  
  <p>But how does 'aggressive' mode decide which contact data to overwrite/keep? I couldn't find any documentation about this.</p>
  
Tags: <duplicate-contacts><scheduling>
Title: Is there any documentation for 'safe' and 'aggressive' merge modes?
ThreadText: # Is there any documentation for 'safe' and 'aggressive' merge modes?
  
  (Asked by: username_0 on 2015-05-21)
  
  We are investigating the 'Process batch merge' scheduled job in CiviCRM, to automatically batch merge duplicate contacts. This calls api.job.processBatchMerge which seems to take the rule to use as a parameter and also a mode, 'safe' or 'aggressive'.
  
  'Safe' mode skips the merge if there are conflicts (which is probably best for an automated process!)
  
  But how does 'aggressive' mode decide which contact data to overwrite/keep? I couldn't find any documentation about this.
  
  **Tags:** duplicate-contacts, scheduling
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-21. Score: 10 | Accepted answer
  
  Its generally a contact with lower ID that's preserved.
  
  For aggressive merges, fields in conflict are retained from that of higher contact ID. In other words, for fields in conflict, value from higher ID overwrites on that of lower ID.
  
  Preserving of contact, is due to the way dedupe queries are written.
  
  A. Example:
  `INSERT INTO dedupe (id1, id2, weight) SELECT t1.id id1, t2.id id2, 10 weight FROM civicrm_contact t1 JOIN civicrm_contact t2 USING (first_name) WHERE t1.id < t2.id AND t1.first_name IS NOT NULL GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight);`
  
  B. Here is the code and comment that makes it clear - <https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L636>
  
  However with CiviCRM v4.5 and above, you can decide the biasing (which contact to preserve) using merge hook - <https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Dedupe/Merger.php#L632>
  
  Here is an implementation example where a contact with maximum number of contributions is preserved - <https://github.com/civicrm/civicrm-drupal/blob/7.x-4.5/civitest.module.sample#L1279>
  
  Same hook could also be used for deciding which value to preserve by playing with $conflicts variable. Here is an example that we did for one of our client - <https://github.com/veda-consulting/uk.co.vedaconsulting.module.dedupe/blob/master/dedupe.php#L218>
  
  > **Comments:**
  > **username_2**: I've tested this and found a different result. Using Civi 5.45.3. Fields in conflict are retained from that of the lower contact ID. Tested email, phone, address.  
  
  ---
  
  