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

INDEX BY clause

Hi!

I am pretty new in cphalcon. I do have a question concerning raw sql. I want to use INDEX BY but it is not working.

$sql = ' SELECT *'
            . ' FROM Two'
            . ' INNER JOIN One ON One.id= Two.pic_id '
            . ' INDEX BY One.id '
            . ' WHERE One.category_id IN (1,2,3,4,...) '
            . ' ORDER BY RAND() ';

$query = $this->di->get('modelsManager')->createQuery($sql);
    $result_query = $query->execute()>setHydrateMode(Resultset::HYDRATE_ARRAYS);

The error comes up "Syntax error, unexpected token IDENTIFIER(INDEX)" - in symfony it is working.

One.id is Autoincrement and unsigend integer!

I migrate from symfony to the wonderful and beautiful phalcon. I am new in phalcon. If it is double sorry!

UPDATE: MySql

What kind of database you use?

edited May '18

Update my question - sorry. Database: MySql

But okay, I just use PDO. That is working as well! I guess it was INDEX BY from Doctrine.



43.9k

Hi,

just curious: can you tell me for what this query part is usefull ?

' INDEX BY One.id '

performance, caching ... ?????