2

I have a query which is a little complicated:

(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)

How can i change this query to Zend_Db_Select object?

1 Answer 1

2

To build a UNION query with Zend_Db_Select, first build each subquery as individual Zend_Db_Select objects, and then union() them together:

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

$unionSelect = $db->select()->union($catSelect, $newsSelect);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.