Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-10816

Custom search with "Distinct" fails when used as a smart group

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Duplicate
    • Affects Version/s: 4.2.1
    • Fix Version/s: Unscheduled
    • Component/s: Core CiviCRM
    • Labels:
      None
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      When I have a custom search where the "select" clause starts with the word "Distinct", it run normally if I run it directly. However, if I try to save it as a smart group then it fails.

      The problem seems to be in file CRM/Contact/BAO/GroupContactCache.php
      around line 344: $insertSql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) ($selectSql);";

      If I copy and paste the SQL from above, it starts out
      "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) (SELECT 63 as group_id, DISTINCT contact_a.id as contact_id FROM civicrm_contact contact_a "...

      If I remove the word "DISTINCT" from the statement, then it works fine.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sgladstone Sarah Gladstone
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: