您好我需要使用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'))
答案 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 queries
和zf-made ones
。
我自己不建议将Zend_Db_Select用于复杂且几乎不常用的查询。