We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Subqueries - Select * from subquery

Is it possible to run query:

$this->modelsManager->executequery('SELECT avg(a) FROM (SELECT sum(a) AS a, b, ,c FROM ...) AS sub')

?

Important part is SELECT FROM subquery. Beacuse I got exception:

Phalcon\Mvc\Model\Exception: Syntax error, unexpected token (, near to 'SELECT sum(a) AS a... 

So is it possible to run such query with modelsManager?

I use Palcon 2.1.x



58.4k

Hello

You can try edit your sql the above to be like this:

$sql = "SELECT avg(a) FROM (SELECT sum(a) AS a, b, ,c FROM ...) AS sub";
$this->modelsManager->executequery($sql)