2

我有一个有点复杂的查询:

(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对象?

4

1 回答 1

2

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

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

$unionSelect = $db->select()->union($catSelect, $newsSelect);
于 2010-10-01T18:32:50.877 回答