W3cubDocs

/Drupal 8

public function Select::union

public Select::union(SelectInterface $query, $type = '')

Add another Select query to UNION to this one.

Union queries consist of two or more queries whose results are effectively concatenated together. Queries will be UNIONed in the order they are specified, with this object's query coming first. Duplicate columns will be discarded. All forms of UNION are supported, using the second '$type' argument.

Note: All queries UNIONed together must have the same field structure, in the same order. It is up to the caller to ensure that they match properly. If they do not, an SQL syntax error will result.

Parameters

$query: The query to UNION to this query.

$type: The type of UNION to add to the query. Defaults to plain UNION.

Return value

\Drupal\Core\Database\Query\SelectInterface The called object.

Overrides SelectInterface::union

File

core/lib/Drupal/Core/Database/Query/Select.php, line 670

Class

Select
Query builder for SELECT statements.

Namespace

Drupal\Core\Database\Query

Code

public function union(SelectInterface $query, $type = '') {
  // Handle UNION aliasing.
  switch ($type) {
    // Fold UNION DISTINCT to UNION for better cross database support.
    case 'DISTINCT':
    case '':
      $type = 'UNION';
      break;

    case 'ALL':
      $type = 'UNION ALL';
    default:
  }

  $this->union[] = array(
    'type' => $type,
    'query' => $query,
  );

  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!Select.php/function/Select::union/8.1.x