Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

SubQuery column

Hi, i got a problem in my query with phalcon 2.0.2 subquery in column is not working..

Error

PhalconException: Syntax error, unexpected token SELECT, near to ' count(id_midias)

Query

$phl = "SELECT m.,mg., (SELECT idmidias from \Apps\Models\MidiasXGalerias where idgalerias = mg.id) as total FROM \Apps\Models\MidiasGalerias AS mg LEFT JOIN \Apps\Models\Midias AS m ON m.id = mg.idmidias WHERE mg.id IN (SELECT idmidias from \Apps\Models\MidiasXGalerias where id_galerias = mg.id), mg.tipo = 'midia'";

I am having the same, It seems phalcon does not allow to have subquery in coulmn selection. Reported it on https://github.com/phalcon/cphalcon/issues/10453



9.6k

using PDO(Postgres or Mysql... ) you can to make subquery

edited Jun '15

I have executed this query as raw sql and get resultset with simple resultset type that work very well for me.

        // Base model
          $bm = new BaseModel();

          // Execute the query
         $rs = new Phalcon\Mvc\Model\Resultset\Simple(null, $bm, $bm->getReadConnection()->query($sql));