3

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.

1 Answer 1

10

Ok I fix this. The problem was in

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

Should be:

->from(new Zend_Db_Expr('('.$oSubSelect.')'),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.