How to make view to group by only one field? I have a view with multiple fields and the fields have multiple values, so I get many duplicates in results.
When I try to use distinct, nothing happens, because select distinct does not affect on multiple values. I have predictable, but non desired result.

When aggregation is disabled I don't have any "groupby" directives in resulting SQL.

When I enable aggregation, I see in resulting SQL the following:

GROUP BY field_data_field_tour_short_name_node_entity_type, 
field_data_field_tour_short_name_field_tour_short_name_value, node_title, 
nid_1, field_data_field_arr_dates_node_entity_type, 
field_data_field_arr_dates_field_arr_dates_value, 
field_data_field_tour_duration_node_entity_type, 
field_data_field_tour_duration_field_tour_duration_tid, 
field_data_field_tour_minimal_price_node_entity_type, 
field_data_field_tour_minimal_price_field_tour_minimal_price


So, as you can see, I have ALL the fields in my view.

When I disable aggregation and try to use hook_views_query alter

$query-&gt;add_field('node', 'nid', 'nid', array('function' =&gt; 'groupby'));
$query-&gt;add_groupby('node.nid');


I get the following:

GROUP BY node.nid, field_data_field_tour_short_name_node_entity_type, 
field_data_field_arr_dates_node_entity_type, 
field_data_field_tour_duration_node_entity_type, 
field_data_field_tour_minimal_price_node_entity_type


As you can see, I get less fields, but not one.

But I need simply:

GROUP BY node.nid


How can I get grouping by only on field instead of many?

UPDATE: I found the following strings in views_plugin_query_default.inc

$groupby = array_unique(array_merge($this-&gt;groupby, $non_aggregates));
  foreach ($groupby as $field) {
    $query-&gt;groupBy($field);
  }


So views for some reason add other fields to groupby if groupby is present.
How to avoid this adding? I could change the file, but this is not proper way.
I had the same problem.
Try to implement the group by in hook_views_pre_execute, it's work for me.

function MYMODULE_views_pre_execute(&amp;$view){
  if ($view-&gt;name == 'YOUR_VIEWS' &amp;&amp;  $view-&gt;current_display == 'SOME_DISPLAY') {   
    $view-&gt;build_info['query']-&gt;groupBy('node.nid');
  }
}


If you are using a pager, updating $view->build_info['count_query'] with the same changes should keep the pager consistent with the query results.