将复杂的查询更改为Zend_Db_Select对象

时间:2010-10-01 17:40:08

标签: zend-framework zend-db-select

我的查询有点复杂:

(SELECT category_id AS id, content_title AS title, content AS detail, 'content' AS type
 FROM category_content
 WHERE $where
 ORDER BY id DESC)
UNION
(SELECT news_id AS id, news_title AS title, news_detail AS detail, 'news' AS type
 FROM news
 WHERE $where
 ORDER BY id DESC)

如何将此查询更改为Zend_Db_Select对象?

1 个答案:

答案 0 :(得分:2)

要使用Zend_Db_Select构建UNION查询,首先将每个子查询构建为单独的Zend_Db_Select对象,然后将它们组合在一起:

$catSelect = $db->select()-> ... ;
$newsSelect = $db->select()-> ... ;

$unionSelect = $db->select()->union($catSelect, $newsSelect);