I am moving my web application from zf1 to zf2 and among the problems I have with sql queries, I can't figure out how to make a union.
I used to be able to make
$select->union($select1, $select2, $select3)
but the Zend\Db\Sql\Select does not have an union()
method anymore.
Is there still a way to make an union in a query with zf2?
I use this https://github.com/zendframework/zf2/pull/3962. (union of two select queries).
Just to complete this answer, I use this to combine/union of 3 selects :
$Sql = new Sql ( $adapter );
Be careful order by not work with combine ! see ZF2 Union + Pagination
Here is a "heavy workaround" example for four SELECTs combined by UNION:
This will win no price but maybe someone can improve on this.
The last two lines are important. You can parse any UNION query you like.
As an alternative for those wanting ease with >1 UNIONs, ZF2 has a dedicated class Zend\Db\Sql\Combine:
or
(new Combine)->union($select);