New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAVING after nested SELECT doesn't work correctly in PHQL #12548

Closed
nsossonko opened this Issue Jan 13, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@nsossonko
Copy link
Contributor

nsossonko commented Jan 13, 2017

SELECT grandParent.id, SUM(parent.total) AS total
FROM Parents AS parent
INNER JOIN GrandParents AS grandParent
ON parent.grandParent = parent.id
WHERE NOT EXISTS (
  SELECT * FROM Childs AS child
  WHERE parent.id = child.parent
)
HAVING total > 1

That causes the PHQL parser to throw an exception that "total is not a column". If I switch to:
"HAVING SUM(parent.total) > 1" it works fine.

PHP 7 with Phalcon 3.0 (master).

@Jurigag

This comment has been minimized.

Copy link
Member

Jurigag commented Jan 13, 2017

Im guessing PHQL is just following SQL standard which doesn't allow aliases to be used for HAVING. Other engines like for example MySQL can allow it, but this is not part of sql standard.

@nsossonko

This comment has been minimized.

Copy link
Contributor Author

nsossonko commented Jan 13, 2017

It allows using the alias when not using a subquery...

@Jurigag

This comment has been minimized.

Copy link
Member

Jurigag commented Jan 13, 2017

Oh okay then.

@stale

This comment has been minimized.

Copy link

stale bot commented Apr 16, 2018

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment