Duplicates b/c of Node References, Views "Group By" not helping I have a view that displays all 'parent' nodes referenced from 'child' nodes. I just want to list the titles of the referenced nodes, but because there can be multiple 'child' nodes referencing the parent nodes, my view displays the 'parent' node titles multiple times (depending on how many child nodes refer to the parent).

I was trying to use Views 3.x's new 'Grouping' feature to group all nodes by nid, but that didn't seem to make a difference. I tried using an nid that was grouped in the filters section, and an nid that was grouped in the fields section, but it didn't matter.

I could do a views_pre_render and just remove the duplicates manually, but that's messy, and would also screw up the pager. (See here for something along those lines: http://capellic.com/blog/cure-duplicate-nodes-in-a-view).

Is there a better way to do this, or something I'm overlooking?

I also tried using the following hook_views_query_alter() hook:

/**
 * Implements hook_views_query_alter().
 */
function custom_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'my_subscriptions' &amp;&amp; $view-&gt;current_display == 'my_networks') {
    $query-&gt;groupby[] = 'node_field_data_field_list_network_nid';
  }
}


But still no dice...

Here's the query being generated by views:


SELECT DISTINCT node_field_data_field_list_network.nid AS node_field_data_field_list_network_nid, node_field_data_field_list_network.title AS node_field_data_field_list_network_title, node.title AS node_title, node.nid AS nid
FROM 
{node} node
INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND (flag_content_node.fid = :views_join_condition_0 AND flag_content_node.uid = :views_join_condition_1)
LEFT JOIN {field_data_field_list_network} field_data_field_list_network ON node.nid = field_data_field_list_network.entity_id AND (field_data_field_list_network.entity_type = :views_join_condition_2 AND field_data_field_list_network.deleted = :views_join_condition_3)
INNER JOIN {node} node_field_data_field_list_network ON field_data_field_list_network.field_list_network_nid = node_field_data_field_list_network.nid
INNER JOIN {users} users ON node.uid = users.uid
WHERE (( (node.status = '1') AND (node_field_data_field_list_network.type IN  ('network')) AND (users.uid = '1' ) ))
ORDER BY node_title DESC
LIMIT 3 OFFSET 0
Well, as it turns out, I avoided this issue by adding another filter, on the 'list' nodes (the children), and I'm lucky that I have one child 'list' node per network that has a unique flag (a 'master' checkbox field that can only be checked on one child per parent 'network' node).

I filtered to only child 'list' nodes that contain that flag, and this means that my parent 'network' nodes only show once.

I still wish I didn't have to do it this way, though. If anyone else can think of a way to actually get a distinct set of nids/titles without my having to use the 'master' flag on the child nodes, I'll definitely mark that answer correct.