diff --git a/search_api_db/src/Plugin/search_api/backend/Database.php b/search_api_db/src/Plugin/search_api/backend/Database.php
index d167241..94f26f5 100644
--- a/search_api_db/src/Plugin/search_api/backend/Database.php
+++ b/search_api_db/src/Plugin/search_api/backend/Database.php
@@ -2259,7 +2259,7 @@ class Database extends BackendPluginBase implements PluginFormInterface {
         $select->range(0, $limit);
       }
       if ($facet['min_count'] > 1) {
-        $select->having('num >= :count', array(':count' => $facet['min_count']));
+        $select->having('COUNT(DISTINCT t.item_id) >= :count', array(':count' => $facet['min_count']));
       }
 
       $terms = array();
@@ -2478,7 +2478,7 @@ class Database extends BackendPluginBase implements PluginFormInterface {
       $db_query->addExpression('COUNT(DISTINCT item_id)', 'results');
       $db_query->fields('t', array('word'))
         ->groupBy('word')
-        ->having('results <= :max', array(':max' => $max_occurrences))
+        ->having('COUNT(DISTINCT item_id) <= :max', array(':max' => $max_occurrences))
         ->orderBy('results', 'DESC')
         ->range(0, $limit);
       $incomp_len = strlen($incomplete_key);
