diff --git includes/database/select.inc includes/database/select.inc
index 6e29541..9d0ed6e 100644
--- includes/database/select.inc
+++ includes/database/select.inc
@@ -94,6 +94,24 @@ interface SelectQueryInterface extends QueryConditionInterface, QueryAlterableIn
   public function &getOrderBy();
 
   /**
+   * Returns a reference to the group by array for this query.
+   *
+   * Because this method returns by reference, alter hooks may edit the order-by
+   * array directly to make their changes. If just adding additional ordering
+   * fields, however, the use of groupBy() is preferred.
+   *
+   * Note that this method must be called by reference as well:
+   *
+   * @code
+   * $fields =& $query->getGroupBy();
+   * @endcode
+   *
+   * @return
+   *   A reference to the expression array structure.
+   */
+  public function &getGroupBy();
+
+  /**
    * Returns a reference to the tables array for this query.
    *
    * Because this method returns by reference, alter hooks may edit the tables
@@ -622,6 +640,10 @@ class SelectQueryExtender implements SelectQueryInterface {
     return $this->query->getOrderBy();
   }
 
+  public function &getGroupBy() {
+    return $this->query->getGroupBy();
+  }
+
   public function &getTables() {
     return $this->query->getTables();
   }
@@ -1029,6 +1051,10 @@ class SelectQuery extends Query implements SelectQueryInterface {
     return $this->order;
   }
 
+  public function &getGroupBy() {
+    return $this->group;
+  }
+
   public function &getTables() {
     return $this->tables;
   }
@@ -1284,11 +1310,21 @@ class SelectQuery extends Query implements SelectQueryInterface {
 
     if (!$count->distinct) {
       // When not executing a distinct query, we can zero-out existing fields
-      // and expressions.
+      // and expressions that are not used by a GROUP BY.  Fields listed in
+      // the GROUP BY clause need to be present in the query.
+      $group_by = array_keys($count->getGroupBy());
       $fields =& $count->getFields();
-      $fields = array();
+      foreach (array_keys($fields) as $field) {
+        if (!empty($group_by[$field])) {
+          unset($fields[$field]);
+        }
+      }
       $expressions =& $count->getExpressions();
-      $expressions = array();
+      foreach (array_keys($expressions) as $field) {
+        if (!empty($group_by[$field])) {
+          unset($fields[$field]);
+        }
+      }
 
       // Also remove 'all_fields' statements, which are expanded into tablename.*
       // when the query is executed.
@@ -1297,6 +1333,10 @@ class SelectQuery extends Query implements SelectQueryInterface {
       }
     }
 
+    // If we've just removed all fields from the query, make sure there is at
+    // least one so that the query still runs.
+    $count->addExpression('1');
+
     // Ordering a count query is a waste of cycles, and breaks on some
     // databases anyway.
     $orders = &$count->getOrderBy();
@@ -1309,10 +1349,10 @@ class SelectQuery extends Query implements SelectQueryInterface {
       $count->distinct = FALSE;
     }
 
-    // COUNT() is an expression, so we add that back in.
-    $count->addExpression('COUNT(*)');
+    $query = db_select($count);
+    $query->addExpression('COUNT(*)');
 
-    return $count;
+    return $query;
   }
 
   public function __toString() {
