$select = $logAdapter->select(); // an instance of Zend_Db_Select class
$select->union(array(
"SELECT Country,Name
FROM ManualLog_TheNew",
"SELECT Country,Name
FROM ManualLog_TheOld"),Zend_Db_Select::SQL_UNION_ALL);
$select->order("$param->orderBy")
->limit($param->length,$param->offset);
This work, but when I insert where() method before $select->order(), will throw error.
$select->where('ManualLog_TheOld.OperateTime >= ?' => "2014-06-30");
Error is:
<b>Fatal error</b>: Uncaught exception 'Zend_Db_Select_Exception' with message 'Invalid use of where clause with UNION' in /xxx/code/ZendFramework/Zend/Db/Select.php:880
I've been frustrated for about two days, please help me. Thank you.
@Claudio Venturini
I tried your answer, still have two questions:
1 The sql printed out are:
Warning: strpos() expects parameter 1 to be string, array given in /code/ZendFramework/Zend/Db/Select.php on line 739
Warning: explode() expects parameter 2 to be string, array given in /code/ZendFramework/Zend/Db/Select.php on line 740
Warning: strpos() expects parameter 1 to be string, array given in /code/ZendFramework/Zend/Db/Select.php on line 739
Warning: explode() expects parameter 2 to be string, array given in /code/ZendFramework/Zend/Db/Select.php on line 740
SELECT `ManualLog_TheOld`.`Country`
FROM `` AS `ManualLog_TheOld`
WHERE (OperateTime >= '2014-06-30')
UNION ALL
SELECT `ManualLog_TheNew`.`Country`
FROM `` AS `ManualLog_TheNew`
WHERE (OperateTime >= '2014-06-30')
ORDER BY `OperateTime` desc LIMIT 200
How to remove the from ``...as?
2 When I remove the from `` ... as and execute the sql, I got error below:
Error Code: 1054
Unknown column 'ManualLog_TheNew.OperateTime' in 'order clause'
But I have OperateTime field! What's wrong?
PS: I've got it, I should query the OperateTime field out too.