2010-10-01 69 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);