PHP-MySQLi-Database-Class icon indicating copy to clipboard operation
PHP-MySQLi-Database-Class copied to clipboard

Request: Union and Union All

Open flaviolaino opened this issue 9 years ago • 3 comments

What about add a method union() (and/or unionAll)? May be like this:

$query_1 = $db->addUnion();
$query_1->where('...', '...')->get('table_1');

$query_2 = $db->addUnion();
$query_2->where('...', '...')->get('table_2');

$result = $db->fromUnions($query_1, $query_2)->orderBy('common_field')->get();

flaviolaino avatar Feb 27 '17 15:02 flaviolaino

Hi , yeah i'am interesting too! It will be usefull! Thank's.

MazettePatacaisse avatar May 21 '17 18:05 MazettePatacaisse

i think we can do that with a subqueries.

$q1 = $db->subQuery();
$q1->get ("users");
$q2 = $db->subQuery();
$q2->get ("clients");
$res = $db->union([$q1, $2]') ->orderBy('common_field')->get();
$res = $db->unionAll([$q1, $2]') ->orderBy('common_field')->get();

avbdr avatar Jun 02 '17 01:06 avbdr

@avbdr TIL there is a union function, that's pretty handy.

Edit: Nvm, can't seem to find it

douglasg14b avatar Jun 14 '17 18:06 douglasg14b