开发者

How execute query with subqueries in zend framework

开发者 https://www.devze.com 2023-02-08 20:04 出处:网络
Hi I need write this sql with Zend_Db_Select, but I dont know how I can write subqueries. I would appreciate any help. Thanks.

Hi I need write this sql with Zend_Db_Select, but I dont know how I can write subqueries. I would appreciate any help. Thanks.

SELECT * FROM advert WHERE categoryId
           IN (
             SELECT id
              FRO开发者_如何学JAVAM `tree`
              WHERE `lft` BETWEEN 
               (SELECT lft FROM tree WHERE id = '2') AND 
               (SELECT rgt FROM tree WHERE id = '2'))


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


Maybe this answer will help you decide between using standard sql queries and zf-made ones.

I myself don't recommend using Zend_Db_Select for complex and scarcely used queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号