I'm pretty sure this is not possible in Zend Framework (I have searched the Web, the documentation and issue tracker) but I just want to make sure so I'm asking here.
$select = $this->select();
$select->union($select1, $select2);
That doesn't work of course. To explain what I need. I need to use UNION() to merge 2 tables in a SELECT query, I know I could just do:
$select = "$select1 UNION $select2";
The problem is that would return a string and I need to get a select object so I can use it with Zend_Paginator.
I have already solved the issue by modifying my database architecture but I'm just curious if there is some workaround for this.
This practical example shows a function that returns a rowset of either latest or if a available favourite blog entries of a specific year (artwork blog):
Here's what I've done to make a union:
Remember
Db_Select
's__toString
will print out the SQL generated by that select, to help you debug.Zend_Db_Select has a union method so I'd have thought it is possible, if you can build your query using a select object. I haven't used Zend_Db_Select (or the table subclass) with union but I'd imagine you can do something like
This is how it works for me:
After getting the necessary data in both queries the UNION syntax goes like this:
a complete example:
and the generated query:
SELECT
reservations
.* FROMreservations
WHERE (id='5658') UNION SELECTres_finished
.* FROMres_finished
WHERE (id='5658') UNION SELECTres_cancel
.* FROMres_cancel
WHERE (id='5658') UNION SELECTres_trash
.* FROMres_trash
WHERE (id='5658')