Index: /elgg/branches/elgg1.5/engine/lib/tags.php =================================================================== --- /elgg/branches/elgg1.5/engine/lib/tags.php (revision 268) +++ /elgg/branches/elgg1.5/engine/lib/tags.php (revision 377) @@ -137,5 +137,5 @@ $query .= ' and ' . get_access_sql_suffix("e"); // Add access controls - $query .= " group by msvalue.string having total > {$threshold} order by total desc limit {$limit} "; + $query .= " group by msvalue.string having count(msvalue.id) > {$threshold} order by count(msvalue.id) desc limit {$limit} "; return get_data($query); Index: /elgg/branches/elgg1.5/engine/lib/relationships.php =================================================================== --- /elgg/branches/elgg1.5/engine/lib/relationships.php (revision 363) +++ /elgg/branches/elgg1.5/engine/lib/relationships.php (revision 377) @@ -662,5 +662,5 @@ if (!$count) { $query .= " group by e.guid,e.type,e.subtype,e.owner_guid,e.site_guid,e.container_guid,e.access_id,e.time_created,e.time_updated,e.enabled ";//postgres requires all fields being selected to be listed in the group by clause. - $query .= " order by total desc limit {$limit} offset {$offset}"; // Add order and limit + $query .= " order by count(distinct e.guid) desc limit {$limit} offset {$offset}"; // Add order and limit return get_data($query, "entity_row_to_elggstar"); } else {