I know this question has already been answered, but for some of use these solutions don't work. However, after doing some research I found a solution that does work for my needs.
I found a really useful workaround that allowed me to fix this. I have posted the code snippet to DropBucket. Basically you implement a Drupal 7 query alter hook that checks all views queries for query comments that specify a groupby clause and field. Then it adds that groupby to the SQL query.
/**
* Found this trick on theoleschool.com.
*
* Description: Allows the view developer to specify the query
* group by action in the query comments. Great way to force the
* removal of duplicates.
*
* Just go into your query comments and type in "groupby:" with
* that colon followed by the field you want to group by.
*
* Examples...
* groupby:node.nid
* groupby:file_managed_file_usage.fid
*
* Ref-Comment: http://theoleschool.com/comment/496#comment-496
* Ref-Article: http://theoleschool.com/blog/using-hookviewsalter-add-group-statement
*/
function mymodule_query_alter(QueryAlterableInterface $query) {
if ($query->hasTag('views')) {
static $count;
$view =& $query->getMetaData('view');
if (strstr($groupby = $view->query->options['query_comment'], 'groupby')) {
list($action, $field) = explode(':', $groupby);
if (strlen($field) > 0) {
$query->groupBy($field);
}
}
}
}
http://dropbucket.org/node/153
The source reference is in the comments on the page.