mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2836: DQL errors when attempting to use GROUP BY MAX(field) #2981
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 26, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user intel352:
Attempting to run DQL similar to:
SELECT a FROM ClassName a GROUP BY MAX(a.depth)
Throws error:
[Semantical Error] line 0, col 250 near 'MAX(ao.depth)': Error: Cannot group by undefined identification or result variable.
Per docs, MAX is allowed within GROUP BY: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#aggregate-functions
If this error is due to some omission on my part, then perhaps the docs should be extended to show a valid GROUP BY MAX() usage, or the error message expanded for a better hint.
@doctrinebot commented on GitHub (Dec 3, 2013):
Comment created by @ocramius:
Grouping by MAX() is not supported, as MAX() is already an aggregation
@doctrinebot commented on GitHub (Dec 3, 2013):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Dec 3, 2013):
Comment created by intel352:
Shame, because that is useful functionality in SQL. So I assume this means the documentation will be correct then?
@doctrinebot commented on GitHub (Dec 3, 2013):
Comment created by @ocramius:
[~intel352] did you check if the EBNF allows that?
@doctrinebot commented on GitHub (Dec 3, 2013):
Comment created by intel352:
Per the doc link in my initial report, the docs say that the aggregation functions are allowed in both SELECT and GROUP BY clauses.
{quote}The following aggregate functions are allowed in SELECT and GROUP BY clauses: AVG, COUNT, MIN, MAX, SUM{quote}
Searching EBNF in same page, one of items supported for GROUP BY is:
{quote}/** ResultVariable identifier usage of mapped field aliases (the "total" of "COUNT() AS total") */
ResultVariable = identifier{quote}
So I assume that means we'd have to move AVG, COUNT, MIN, MAX, SUM into the SELECT statement, using SELECT AS , and then GROUP BY ?
@doctrinebot commented on GitHub (Dec 3, 2013):
Comment created by @ocramius:
[~intel352] I think the syntax allows that, but you should give it a try. I don't see how that is supposed to work given how GROUP BY works in various RDBMS implementations