Perhaps, but hardly anyone will write a request for you.
My recommendation for resolving such a query is to write each individual subquery as its own Zend_Db_Select object, and then build the final query using subqueries for which you already have objects.
Zend_Db_Select does not directly support the IF function, so for this you will need to use Zend_Db_Expr to add this operator to your selection.
Here is a basic example of what I'm talking about. Let's build the following query:
SELECT IF(msg.toId = 'drew010', msg.fromId, msg.toId), id, name, age, history.ip FROM users JOIN history ON users.id = history.userId WHERE users.id = ( SELECT id FROM users WHERE loginCount > 1000 ) GROUP BY id, ORDER BY age DESC
First create a subheading that selects users where loginCount > 1000.
$subquery1 = $db->select() ->from('users', array('id')) ->where('loginCount > ?', 1000);
Then create an external query using the IF function:
$cols = array( new Zend_Db_Expr('IF(' . $db->quoteInto('msg.toId = ?', 'drew010') . '), msg.fromId, msg.toId'), 'id', 'name', 'age' ); $query = $db->select() ->from('users', $cols) ->join('history', 'users.id = history.userId', array('ip')) ->where('id = ?', $subquery1) ->group('id') ->order('age DESC'); echo $query;
Output:
SELECT IF(msg.toId = 'drew010', msg.fromId, msg.toId), `users`.`id`, `users`.`name`, `users`.`age`, `history`.`ip` FROM `users` INNER JOIN `history` ON users.id = history.userId WHERE id = ( (SELECT `users`.`id` FROM `users` WHERE (loginCount > 1000)) ) GROUP BY `id` ORDER BY `age` DESC
Thus, the way is to first split the entire query into separate queries, and then build an external query. Just have patience and do it slowly. This and read the Zend_Db_Select docs to get a complete picture of what you have for you.