diff --git a/includes/query.inc b/includes/query.inc
index a25fb9d..6a0d5d8 100644
--- a/includes/query.inc
+++ b/includes/query.inc
@@ -970,11 +970,18 @@ class views_query {
       }
     }
 
-    if ($has_aggregate || $this->groupby) {
+    if (empty($this->no_aggregates_in_groupby)) $this->no_aggregates_in_groupby = FALSE;
+
+    if (($has_aggregate || $this->groupby) AND !$this->no_aggregates_in_groupby) {
       $groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n";
       if ($this->having) {
         $having = $this->condition_sql('having');
       }
+    } else if ($this->no_aggregates_in_groupby) {
+      $groupby = "GROUP BY " . implode(', ', $this->groupby) . "\n";
+      if ($this->having) {
+        $having = $this->condition_sql('having');
+      }
     }
 
     if (!$get_count_optimized) {
