2011-02-07 130 views
1

您好我需要用Zend_Db_Select編寫此sql,但我不知道如何編寫子查詢。我將不勝感激任何幫助。謝謝。如何在zend框架中使用子查詢執行查詢

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

回答

0

也許this answer將幫助您使用standard sql querieszf-made ones之間做出選擇。

我自己並不建議使用Zend_Db_Select來處理複雜且很少使用的查詢。

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