2010-10-01 168 views
2

我有一个查询这是一个有点复杂:改变一个复杂的查询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对象?

回答

2

为了建立与Zend_Db_Select对象UNION查询,第一一起构建每个子查询作为单独Zend_Db_Select对象对象,然后联合()它们:

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

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