изменить сложный запрос на объект Zend_Db_Select - PullRequest
2 голосов
/ 01 октября 2010

У меня есть запрос, который немного сложнее:

(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 Ответ

2 голосов
/ 01 октября 2010

Чтобы построить запрос UNION с Zend_Db_Select, сначала создайте каждый подзапрос как отдельные объекты Zend_Db_Select, а затем объедините () их вместе:

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

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