diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 2dac2720acf3..764f57325bc1 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4788,9 +4788,11 @@ public function getCachedContacts($cacheKey, $offset, $rowCount, $includeContact $onlyDeleted = in_array(array('deleted_contacts', '=', '1', '0', '0'), $this->_params); list($select, $from, $where) = $this->query(FALSE, FALSE, FALSE, $onlyDeleted); $from = " FROM civicrm_prevnext_cache pnc INNER JOIN civicrm_contact contact_a ON contact_a.id = pnc.entity_id1 AND pnc.cacheKey = '$cacheKey' " . substr($from, 31); - $groupBy = self::getGroupByFromSelectColumns($this->_select, array('contact_a.id')); + $order = " ORDER BY pnc.id"; + $groupByCol = array('contact_a.id', 'pnc.id'); + $groupBy = self::getGroupByFromSelectColumns($this->_select, $groupByCol); $limit = " LIMIT $offset, $rowCount"; - $query = "$select $from $where $groupBy $limit"; + $query = "$select $from $where $groupBy $order $limit"; return CRM_Core_DAO::executeQuery($query); } diff --git a/CRM/Core/BAO/PrevNextCache.php b/CRM/Core/BAO/PrevNextCache.php index 271673d03073..a3d6f44123a4 100644 --- a/CRM/Core/BAO/PrevNextCache.php +++ b/CRM/Core/BAO/PrevNextCache.php @@ -506,6 +506,7 @@ public static function getSelection($cacheKey, $action = 'get', $entity_table = WHERE cacheKey LIKE %1 $actionGet $entity_whereClause +ORDER BY id "; $params[1] = array("{$cacheKey}%", 'String');