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オブジェクトとして作成し、次にそれらを一緒にunion()します。

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

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