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

Query that works in MySQL Workbench but not in PHQL

Hello guys!

I got this error:

SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'users_info'

When I run this PHQL:

 $phql = "
      SELECT Users.id, UsersInfo.name
      FROM Users, UsersParent
      INNER JOIN UsersInfo ON UsersParent.child_user_id = UsersInfo.user_id
      WHERE Users.id = UsersParent.parent_user_id AND UsersParent.parent_user_id = :parent_id:";

As you can see is a hierarchical relation. I don't know why I'm getting the error, in MySQL Workbench works!

Better to check what is really runned sql by adding db listener to beforeQuery event.