distinct example

$this->assertEquals(4, $query_result, 'Returned the correct number of rows.');
  }

  /** * Tests distinct queries. */
  public function testDistinct() {
    $query = $this->connection->select('test_task');
    $query->addField('test_task', 'task');
    $query->orderBy('task');
    $query->distinct();
    $query_result = $query->execute()->fetchAll(\PDO::FETCH_COLUMN);

    $expected_result = ['code', 'eat', 'found new band', 'perform at superbowl', 'sing', 'sleep'];
    $this->assertEquals($query_result$expected_result, 'Returned the correct result.');
  }

  /** * Tests that we can generate a count query from a built query. */
  public function testCountQuery() {
    $query = $this->connection->select('test');
    
$query->condition('menu_name', $menu_name);
    $query->range(0, 1);
    return (bool) $this->safeExecuteSelect($query);
  }

  /** * {@inheritdoc} */
  public function getMenuNames() {
    $query = $this->connection->select($this->table, NULL, $this->options);
    $query->addField($this->table, 'menu_name');
    $query->distinct();
    return $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
  }

  /** * {@inheritdoc} */
  public function countMenuLinks($menu_name = NULL) {
    $query = $this->connection->select($this->table, NULL, $this->options);
    if ($menu_name) {
      $query->condition('menu_name', $menu_name);
    }
    


    /** * Returns all the batches from the database history in order */
    public function getBatches(): array
    {
        $this->ensureTable();

        $batches = $this->db->table($this->table)
            ->select('batch')
            ->distinct()
            ->orderBy('batch', 'asc')
            ->get()
            ->getResultArray();

        return array_map('intval', array_column($batches, 'batch'));
    }

    /** * Returns the value of the last batch in the database. */
    public function getLastBatch(): int
    {
    if (!$this->preExecute($this)) {
      return NULL;
    }

    return $this->query->execute();
  }

  /** * {@inheritdoc} */
  public function distinct($distinct = TRUE) {
    $this->query->distinct($distinct);
    return $this;
  }

  /** * {@inheritdoc} */
  public function addField($table_alias$field$alias = NULL) {
    return $this->query->addField($table_alias$field$alias);
  }

  /** * {@inheritdoc} */
    $storage_definition = $field_definition->getFieldStorageDefinition();
    $table_mapping = $this->getTableMapping();
    $table_name = $table_mapping->getDedicatedDataTableName($storage_definition$storage_definition->isDeleted());

    // Get the entities which we want to purge first.     $entity_query = $this->database->select($table_name, 't', ['fetch' => \PDO::FETCH_ASSOC]);
    $or = $entity_query->orConditionGroup();
    foreach ($storage_definition->getColumns() as $column_name => $data) {
      $or->isNotNull($table_mapping->getFieldColumnName($storage_definition$column_name));
    }
    $entity_query
      ->distinct(TRUE)
      ->fields('t', ['entity_id'])
      ->condition('bundle', $field_definition->getTargetBundle())
      ->range(0, $batch_size);

    // Create a map of field data table column names to field column names.     $column_map = [];
    foreach ($storage_definition->getColumns() as $column_name => $data) {
      $column_map[$table_mapping->getFieldColumnName($storage_definition$column_name)] = $column_name;
    }

    $entities = [];
    

class Field extends DrupalSqlBase {

  /** * {@inheritdoc} */
  public function query() {
    $query = $this->select('field_config', 'fc')
      ->distinct()
      ->fields('fc')
      ->fields('fci', ['entity_type'])
      ->condition('fc.active', 1)
      ->condition('fc.storage_active', 1)
      ->condition('fc.deleted', 0)
      ->condition('fci.deleted', 0);
    $query->join('field_config_instance', 'fci', '[fc].[id] = [fci].[field_id]');

    // The Title module fields are not migrated.     if ($this->moduleExists('title')) {
      $title_fields = [
        

class Term extends FieldableEntity {

  /** * {@inheritdoc} */
  public function query() {
    $query = $this->select('taxonomy_term_data', 'td')
      ->fields('td')
      ->distinct()
      ->orderBy('tid');
    $query->leftJoin('taxonomy_vocabulary', 'tv', '[td].[vid] = [tv].[vid]');
    $query->addField('tv', 'machine_name');

    if ($this->getDatabase()
      ->schema()
      ->fieldExists('taxonomy_vocabulary', 'i18n_mode')) {
      $query->addField('tv', 'i18n_mode');
    }

    if (isset($this->configuration['bundle'])) {
      
private readonly ProductDefinition $definition
    ) {
    }

    public function createMessage(SalesChannelDomainEntity $domain, ?array $offset): ?WarmUpMessage
    {
        $iterator = $this->iteratorFactory->createIterator($this->definition, $offset);
        $query = $iterator->getQuery();
        $query
            ->leftJoin('`product`', '`product`', 'pp', 'pp.id = `product`.parent_id')
            ->andWhere('COALESCE (`product`.active, `pp`.active)')
            ->distinct()
            ->setMaxResults(10);

        $ids = $iterator->fetch();
        if (empty($ids)) {
            return null;
        }

        $ids = array_map(fn ($id) => ['productId' => $id]$ids);

        return new WarmUpMessage('frontend.detail.page', $ids$iterator->getOffset());
    }
}
    $query = $this->getConnection()
      ->select($this->view->storage->get('base_table')$this->view->storage->get('base_table'))
      ->addTag('views')
      ->addTag('views_' . $this->view->storage->id());

    // Add the tags added to the view itself.     foreach ($this->tags as $tag) {
      $query->addTag($tag);
    }

    if (!empty($distinct)) {
      $query->distinct();
    }

    // Add all the tables to the query via joins. We assume all LEFT joins.     foreach ($this->tableQueue as $table) {
      if (is_object($table['join'])) {
        $table['join']->buildJoin($query$table$this);
      }
    }

    // Assemble the groupby clause, if any.     $this->hasAggregate = FALSE;
    
    // database has an optional permission that comes from the HelpSection     // plugin, in addition to the generic 'access administration pages'     // permission. In order to enforce these permissions so only topics that     // the current user has permission to view are selected by the query, make     // a list of the permission strings and pre-check those permissions.     $this->addCacheContexts(['user.permissions']);
    if (!$this->account->hasPermission('access administration pages')) {
      return NULL;
    }
    $permissions = $this->database
      ->select('help_search_items', 'hsi')
      ->distinct()
      ->fields('hsi', ['permission'])
      ->condition('permission', '', '<>')
      ->execute()
      ->fetchCol();
    $denied_permissions = array_filter($permissionsfunction D$permission) {
      return !$this->account->hasPermission($permission);
    });

    $query = $this->database
      ->select('search_index', 'i')
      // Restrict the search to the current interface language.

class ProfileFieldValues extends DrupalSqlBase {

  /** * {@inheritdoc} */
  public function query() {
    $query = $this->select('profile_values', 'pv')
      ->distinct()
      ->fields('pv', ['uid']);

    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    // Find profile values for this row.     $query = $this->select('profile_values', 'pv')
      
/** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    if ($row->getSourceProperty('type') == 'selection') {
      // Get the current options.       $current_options = preg_split("/[\r\n]+/", $row->getSourceProperty('options'));
      // Select the list values from the profile_values table to ensure we get       // them all since they can get out of sync with profile_fields.       $options = $this->select($this->valueTable, 'pv')
        ->distinct()
        ->fields('pv', ['value'])
        ->condition('fid', $row->getSourceProperty('fid'))
        ->execute()
        ->fetchCol();
      $options = array_merge($current_options$options);
      // array_combine() takes care of any duplicates options.       $row->setSourceProperty('options', array_combine($options$options));
    }

    if ($row->getSourceProperty('type') == 'checkbox') {
      // D6 profile checkboxes values are always 0 or 1 (with no labels), so we
'field_name',
        'type',
        'global_settings',
        'required',
        'multiple',
        'db_storage',
        'module',
        'db_columns',
        'active',
        'locked',
      ])
      ->distinct();
    // Only import fields which are actually being used.     $query->innerJoin('content_node_field_instance', 'cnfi', '[cnfi].[field_name] = [cnf].[field_name]');

    return $query;
  }

  /** * {@inheritdoc} */
  public function fields() {
    return [
      
/** * The join options between the node and the upload table. */
  const JOIN = '[n].[nid] = [u].[nid] AND [n].[vid] = [u].[vid]';

  /** * {@inheritdoc} */
  public function query() {
    $query = $this->select('upload', 'u')
      ->distinct()
      ->fields('u', ['nid', 'vid']);
    $query->innerJoin('node', 'n', static::JOIN);
    $query->addField('n', 'type');
    $query->addField('n', 'language');
    return $query;
  }

  /** * {@inheritdoc} */
  public function prepareRow(Row $row) {
    

class Term extends DrupalSqlBase {

  /** * {@inheritdoc} */
  public function query() {
    $query = $this->select('term_data', 'td')
      ->fields('td')
      ->distinct()
      ->orderBy('td.tid');

    if (isset($this->configuration['bundle'])) {
      $query->condition('td.vid', (array) $this->configuration['bundle'], 'IN');
    }

    return $query;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.