union example


  public function range($start = NULL, $length = NULL) {
    $this->query->range($start$length);
    return $this;
  }

  /** * {@inheritdoc} */
  public function union(SelectInterface $query$type = '') {
    $this->query->union($query$type);
    return $this;
  }

  /** * {@inheritdoc} */
  public function groupBy($field) {
    $this->query->groupBy($field);
    return $this;
  }

  

  public function testUnion() {
    $query_1 = $this->connection->select('test', 't')
      ->fields('t', ['name'])
      ->condition('age', [27, 28], 'IN');

    $query_2 = $this->connection->select('test', 't')
      ->fields('t', ['name'])
      ->condition('age', 28);

    $query_1->union($query_2);

    $names = $query_1->execute()->fetchCol();

    // Ensure we only get 2 records.     $this->assertCount(2, $names, 'UNION correctly discarded duplicates.');

    $this->assertEqualsCanonicalizing(['George', 'Ringo']$names);
  }

  /** * Tests that we can UNION ALL multiple SELECT queries together. */
$stmt->where('(s.value LIKE "" OR s.value IS NULL)');
        }

        // Search         if (isset($filters['search'])) {
            $filter = '%' . $filters['search'] . '%';

            $stmt->where('(s.namespace LIKE ? OR s.name LIKE ? OR s.value LIKE ?)', $filter);
            $secondStmt->where('(s1.namespace LIKE ? OR s1.name LIKE ? OR s1.value LIKE ?)', $filter);
        }

        $selectUnion = $this->database->select()->union(['(' . $stmt . ')', '(' . $secondStmt . ')'], Zend_Db_Select::SQL_UNION_ALL);

        if (!empty($order)) {
            $selectUnion->order($order['property'] . ' ' . $order['direction']);
        } else {
            $selectUnion->order('namespace');
        }

        $selectUnion->limit($limit$start);

        $countStmt = clone $selectUnion;
        $countStmt->reset('limitcount')
            
$union_query->addField('tn', 'nid');
        $left_join = "[tn].[tid]";
        if ($this->options['depth'] > 0) {
          $union_query->join('taxonomy_term__parent', "th", "$left_join = [th].[entity_id]");
          $left_join = "[th].[$left_field]";
        }
        foreach (range(1, $count) as $inner_count) {
          $union_query->join('taxonomy_term__parent', "th$inner_count", "$left_join = [th$inner_count].[$right_field]");
          $left_join = "[th$inner_count].[$left_field]";
        }
        $union_query->condition("th$inner_count.entity_id", $tids$operator);
        $subquery->union($union_query);
      }
    }

    // Add the subquery as a join.     $definition['left_table'] = $this->tableAlias;
    $definition['left_field'] = $this->realField;
    $definition['field'] = 'nid';
    $definition['type'] = 'INNER';
    $definition['adjusted'] = TRUE;
    $definition['table formula'] = $subquery;
    $join = Views::pluginManager('join')->createInstance('standard', $definition);

    
Home | Imprint | This part of the site doesn't use cookies.