Union

The Union class is used to create SQL UNION queries, allowing you to combine the results of multiple Select queries into a single result set.

Constants

Methods

addQuery(Select $query)

Adds a Select query to the union.

Example:

use Staple\Query\Union;
use Staple\Query\Select;

$union = new Union();
$union->addQuery(new Select('users_active'));
$union->addQuery(new Select('users_archived'));

setFlag($flag)

Sets the UNION flag to ALL or DISTINCT.

Example:

$union->setFlag(Union::ALL);

orderBy(array|string $order)

Sets the ORDER BY clause for the entire union result.

limit(int|Pager $limit, int $offset)

Sets the LIMIT and OFFSET for the union result.

build()

Builds and returns the full SQL UNION statement.

execute()

Executes the union query and returns a Statement object.