Selecting distinct in a view causes the view to return no results because the query is improperly structured. The preview indicates this will be the query on my view:

SELECT DISTINCT(node.nid) AS nid,
   node.title AS node_title,
   node_data_field_profile_image.field_profile_image_fid AS node_data_field_profile_image_field_profile_image_fid,
   node_data_field_profile_image.field_profile_image_list AS node_data_field_profile_image_field_profile_image_list,
   node_data_field_profile_image.field_profile_image_data AS node_data_field_profile_image_field_profile_image_data,
   node_data_field_profile_image.nid AS node_data_field_profile_image_nid,
   node.type AS node_type,
   votingapi_cache_node.value AS votingapi_cache_node_value
 FROM www_funcoast_node node 
 LEFT JOIN www_funcoast_votingapi_cache votingapi_cache_node ON node.nid = votingapi_cache_node.content_id AND votingapi_cache_node.content_type = 'node'
 LEFT JOIN www_funcoast_content_field_profile_image node_data_field_profile_image ON node.vid = node_data_field_profile_image.vid
 WHERE (node.type in ('artist')) AND (node.status <> 0)
   ORDER BY node_title ASC

Which would work fine, but in the actual query that is run, the first line is written:

SELECT DISTINCT(node.nid) AS DISTINCT(node.nid), node.title AS node_title, 

...and that, of course, fails.

Here's an export of my view:

$view = new view;
$view->name = 'music';
$view->description = 'Listing of bands';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'votingapi_cache' => array(
    'label' => 'Voting results',
    'required' => 0,
    'votingapi' => array(
      'value_type' => '',
      'tag' => '',
      'function' => '',
    ),
    'id' => 'votingapi_cache',
    'table' => 'node',
    'field' => 'votingapi_cache',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Band Name',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_profile_image_fid' => array(
    'label' => '',
    'link_to_node' => 1,
    'label_type' => 'none',
    'format' => 'Teaser_linked',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_profile_image_fid',
    'table' => 'node_data_field_profile_image',
    'field' => 'field_profile_image_fid',
    'relationship' => 'none',
  ),
  'value' => array(
    'label' => 'Rating',
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'appearance' => 'fivestar_views_value_display_handler',
    'exclude' => 0,
    'id' => 'value',
    'table' => 'votingapi_cache',
    'field' => 'value',
    'relationship' => 'votingapi_cache',
  ),
));
$handler->override_option('sorts', array(
  'title' => array(
    'order' => 'ASC',
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'artist' => 'artist',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 0);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'title' => 'title',
    'value' => 'value',
    'teaser' => 'title',
    'field_profile_image_fid' => 'field_profile_image_fid',
  ),
  'info' => array(
    'title' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'value' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'teaser' => array(
      'separator' => '',
    ),
    'field_profile_image_fid' => array(
      'separator' => '',
    ),
  ),
  'default' => 'title',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'music');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Music',
  'description' => '',
  'weight' => '0',
  'name' => 'primary-links',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
$handler = $view->new_display('block', 'Artist\'s Songs', 'block_1');
$handler->override_option('relationships', array());
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
  'field_credit_value' => array(
    'label' => 'Written By',
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_credit_value',
    'table' => 'node_data_field_credit',
    'field' => 'field_credit_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
  'field_song_fid' => array(
    'label' => '',
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_song_fid',
    'table' => 'node_data_field_song',
    'field' => 'field_song_fid',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'field_performer_nid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'node',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'field_performer_nid',
    'table' => 'node_data_field_performer',
    'field' => 'field_performer_nid',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '<?php
    return arg(1);
    

',
'validate_argument_node_type' => array(
'webform' => 0,
'poll' => 0,
'artist' => 0,
'calendar_event' => 0,
'coupon' => 0,
'documentation' => 0,
'movie_showtimes' => 0,
'page' => 0,
'profile' => 0,
'simplenews' => 0,
'song' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'6' => 0,
'1' => 0,
'5' => 0,
'7' => 0,
'8' => 0,
'4' => 0,
'3' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_php' => '',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'song' => 'song',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('style_plugin', 'default');
$handler->override_option('style_options', array(
'grouping' => '',
));
$handler->override_option('exposed_block', TRUE);
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
?>

Comments

merlinofchaos’s picture

Status: Active » Closed (duplicate)

This is a core bug: http://drupal.org/node/284392