如何在zend框架中使用子查询执行查询

时间:2011-02-07 14:11:34

标签: sql mysql zend-framework

您好我需要使用Zend_Db_Select编写此sql,但我不知道如何编写子查询。我将不胜感激任何帮助。感谢。

SELECT * FROM advert WHERE categoryId
           IN (
             SELECT id
              FROM `tree`
              WHERE `lft` BETWEEN 
               (SELECT lft FROM tree WHERE id = '2') AND 
               (SELECT rgt FROM tree WHERE id = '2'))

2 个答案:

答案 0 :(得分:1)

// create the main query
$select = new Zend_Db_Select();

//create the subquery
$subSelect = new Zend_Db_Select();

// using the subquery in main query
$select->where('table.field IN(?)', $subSelect->assemble());

答案 1 :(得分:0)

也许this answer会帮助您决定使用standard sql querieszf-made ones

我自己不建议将Zend_Db_Select用于复杂且几乎不常用的查询。

相关问题