Zend Db Select add subquery to FROM part

zend-db, zend-framework

Solution

Ok I fix this. The problem was in

->from(new Zend_Db_Expr($oSubSelect).' AS temp',

Should be:

->from(new Zend_Db_Expr('('.$oSubSelect.')'),

Problem

I try to build a query with subquery in FROM part using the Zend_Db_Select. Im looking for somthing like this: ``` SELECT COUNT(row_1) AS count_row FROM (SELECT row,row2,... FROM table WHERE row= ...) AS temp WHERE row = 0) ``` So I try to do it like this: ``` $oSubSelect = $this->select() ->setIntegrityCheck(false) ->from('table', array( 'row_id' ) ) ->where(PRFX.'table.id = '.PRFX.'table2.id') ->from(PRFX.'table2',array('row','row2')); $this->select(false) ->setIntegrityCheck(false) ->from(new Zend_Db_Expr($oSubSelect).' AS temp', array( 'COUNT(row_id) AS row_count', ) ); ``` But this gives me an error message. Best regards.

Original source