In views_query->query(), on line 979 of views/includes/query.inc, it merges all non-aggregate fields with aggregate ones when building the GROUP BY clause. This poses a problem for a rather simple view I am trying to build.

The view is to output a listing of users with the blogger role and the title of their latest post.

Because I cannot create a node relationship in a user view, it is a node view. I am using the views_groupby module to group by uid, and count nid (since it requires a count field). views_groupby properly makes a single call to views_query->add_groupby() with uid. This works fine until I add the node title field, because views_query->query() sticks it in the GROUP BY clause, creating a row for every blog post instead of every blogger.

Comments

merlinofchaos’s picture

Status: Active » Closed (works as designed)

This is by design due to requirements of pgsql. Fields in the SELECT must either be in the GROUP BY or use an aggregate function.

derekdunagan’s picture

For anyone who is having similar problems, I found this hook to be useful:

hook_views_pre_execute(&$view)

In it, I altered the actual SQL query in $view->build_info['query']. There is also $view->build_info['count_query']. I am not sure what count_query is for, but I altered it anyway.