How to group by one field
I was able to find a solution by following this example. Here is the code in my case:

function alter_users_query_query_alter($query) {
    if (isset($query-&gt;alterMetaData)) {
        if (isset($query-&gt;alterMetaData['view'])) {
            if($query-&gt;alterMetaData['view']-&gt;name == 'all_users') {
                $fields =&amp; $query-&gt;getGroupBy();

                unset($fields['field-you-want-to-remove']);
                $query-&gt;groupBy('users_name');
            }
        }
    }
}