diff --git a/plugins/views_plugin_query_default.inc b/plugins/views_plugin_query_default.inc index 23f0eb1..886f5fe 100644 --- a/plugins/views_plugin_query_default.inc +++ b/plugins/views_plugin_query_default.inc @@ -1208,7 +1208,25 @@ class views_plugin_query_default extends views_plugin_query { $this->has_aggregate = FALSE; $non_aggregates = array(); - list($non_aggregates) = $this->compile_fields($fields_array, $query); + $this->compile_fields($fields_array, $query); + + foreach ($fields_array as $field){ + if (!empty($field['table'])){ + $name = $field['table'] . '.' . $field['field']; + } + else { + // Ignore SELECT variables, they cannot be used inside of GROUP BY statements as they are not part of any column. + if (preg_match("/^'.*'$/i", $field['field']) > 0){ + continue; + } + + $name = $field['field']; + } + + if (!in_array($name, $non_aggregates)){ + $non_aggregates[] = $name; + } + } if (count($this->having)) { $this->has_aggregate = TRUE;