Answers.Body: <p>The issue you getting has been now <a href="https://github.com/civicrm/civicrm-core/pull/16534" rel="nofollow noreferrer">fixed</a> and will be part of 5.23 release. You can either wait for 5.23 release and upgrade CiviCRM or apply patch from <a href="https://patch-diff.githubusercontent.com/raw/civicrm/civicrm-core/pull/16534.patch" rel="nofollow noreferrer">here</a>. </p>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T14:28:07.603Z
Answers.Text: <3 <3 <3 <3 <3 <3
Answers.UserDisplayName: nielo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T14:31:35.487Z
Answers.Text: Do you know why I did not find an issue on issues.civicrm.org?
Answers.UserDisplayName: nielo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T15:22:46.260Z
Answers.Text: issue.civicrm.org is old. New issues are at https://lab.civicrm.org/groups/dev/-/issues
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-11T14:24:10.967Z
Answers.LastActivityDate: 2020-03-11T14:24:10.967Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>When listing recipients of CiviMail either via advanced search or mailing report¹ I get a wrong row count query. See the where-clause in</p>
  
  <pre><code>SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact_a   
  LEFT JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id
  LEFT JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id
  WHERE  (  AND civicrm_mailing.id IN (2198) )  AND (contact_a.is_deleted = 0) 
  </code></pre>
  
  <p>This is generated by <code>CRM\Contact\Bao\Query.php</code>.</p>
  
  <p>Before I dig down into all the query generating code: Did anybody of you civi gurus out there see this before?</p>
  
  <p>Relevant stacktrace is:</p>
  
  <pre><code>#10 /civicrm/packages/DB/DataObject.php(1607): DB_DataObject-&gt;_query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #11 /civicrm/CRM/Core/DAO.php(420): DB_DataObject-&gt;query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #12 /civicrm/CRM/Core/DAO.php(1496): CRM_Core_DAO-&gt;query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...", TRUE)
  #13 /civicrm/CRM/Contact/BAO/Query.php(4977): CRM_Core_DAO::singleValueQuery("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #14 /civicrm/CRM/Contact/Selector.php(525): CRM_Contact_BAO_Query-&gt;searchQuery(0, 0, NULL, TRUE)
  #15 /civicrm/CRM/Core/Selector/Controller.php(218): CRM_Contact_Selector-&gt;getTotalCount(4, NULL)
  </code></pre>
  
  <p>¹) URI on error is <code>/civicrm/contact/search/advanced?force=1&amp;mailing_id=&lt;MAILING_ID&gt;</code></p>
  
Tags: <core>
Title: DB error on listing mailing recipients. Did anybody see that before?
ThreadText: # DB error on listing mailing recipients. Did anybody see that before?
  
  (Asked by: username_0 on 2020-03-11)
  
  When listing recipients of CiviMail either via advanced search or mailing report¹ I get a wrong row count query. See the where-clause in
  
  ```
  SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact_a   
  LEFT JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id
  LEFT JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id
  WHERE  (  AND civicrm_mailing.id IN (2198) )  AND (contact_a.is_deleted = 0) 
  
  ```
  
  This is generated by `CRM\Contact\Bao\Query.php`.
  
  Before I dig down into all the query generating code: Did anybody of you civi gurus out there see this before?
  
  Relevant stacktrace is:
  
  ```
  #10 /civicrm/packages/DB/DataObject.php(1607): DB_DataObject->_query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #11 /civicrm/CRM/Core/DAO.php(420): DB_DataObject->query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #12 /civicrm/CRM/Core/DAO.php(1496): CRM_Core_DAO->query("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...", TRUE)
  #13 /civicrm/CRM/Contact/BAO/Query.php(4977): CRM_Core_DAO::singleValueQuery("SELECT count(DISTINCT contact_a.id) as rowCount  FROM civicrm_contact contact...")
  #14 /civicrm/CRM/Contact/Selector.php(525): CRM_Contact_BAO_Query->searchQuery(0, 0, NULL, TRUE)
  #15 /civicrm/CRM/Core/Selector/Controller.php(218): CRM_Contact_Selector->getTotalCount(4, NULL)
  
  ```
  
  ¹) URI on error is `/civicrm/contact/search/advanced?force=1&mailing_id=<MAILING_ID>`
  
  **Tags:** core
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-11. Score: 1 | Accepted answer
  
  The issue you getting has been now [fixed](https://github.com/civicrm/civicrm-core/pull/16534) and will be part of 5.23 release. You can either wait for 5.23 release and upgrade CiviCRM or apply patch from [here](https://patch-diff.githubusercontent.com/raw/civicrm/civicrm-core/pull/16534.patch).
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: <3 <3 <3 <3 <3 <3  
  > **username_0**: Do you know why I did not find an issue on issues.civicrm.org?  
  > **username_2**: issue.civicrm.org is old. New issues are at https://lab.civicrm.org/groups/dev/-/issues  
  
  ---
  
  