Merge all members into the same household when using select fields fails with a db error
Overview
When you select the merge option when exporting contacts to Merge Household members into their households and you select fields and the only field you select is addressee you get a DB erorr
Reproduction steps
- Create demo site
- Do a simple advanced searech
- Select some contacts (maybe make sure there is at least one household contact included) and Select export contacts
- Choose to select fields and also choose the Merge Household members into their Households
- Select Addressee as the only field to export
Current behaviour
Get a DB error
DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT contact_a.id as contact_id, contact_a.addressee_id as addressee_id, contact_a.addressee_display as addressee_display, contact_a.addressee_custom as addressee_custom, contact_id_a as refContact FROM civicrm_contact contact_a
INNER JOIN civicrm_relationship crel ON crel.contact_id_b = contact_a.id AND crel.relationship_type_id = 8
INNER JOIN civicrm_contact ctTable ON ctTable.contact_id = contact_id_a WHERE contact_a.is_deleted = 0 AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= 20201224 ) ) GROUP BY crel.contact_id_a [nativecode=1054 ** Unknown column 'ctTable.contact_id' in 'on clause']"]
Expected behaviour
Export should succeed
Environment information
- CiviCRM: Master
- PHP: 7.3
- CMS: Drupal 7.77
- Database: MySQL 5.7