Bug #603 | strange behaviour with MAX without GROUP BY | ||
---|---|---|---|
Submitted: | 6 Jun 2003 4:35 | Modified: | 6 Jun 2003 7:21 |
Reporter: | Martijn Korse | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | OS: | Linux (Linux) | |
Assigned to: | CPU Architecture: | Any |
[6 Jun 2003 4:35]
Martijn Korse
[6 Jun 2003 7:21]
Mark Matthews
This behavior is as specified by the SQL standard. MIN, MAX and SUM are required to return NULL if all of the rows of the column specified by MIN, MAX or SUM are NULL, or if _no_ rows are returned. You will find this same behavior in SQL Server, Oracle or any other database that implements these funtions in a way that follows the SQL standard.
[6 Jun 2003 10:10]
Martijn Korse
> This behavior is as specified by the SQL standard. My Apologies, i was unaware of that > MIN, MAX and SUM are required to return NULL if all of the rows of the column > specified by MIN, MAX or SUM are NULL, or if _no_ rows are returned. Isn't it a bug then that the last query i gave: SELECT MAX(id) AS max_id, MIN(id) AS min_id, '1' FROM users WHERE id>4 GROUP BY '1'; doesn't return any rows? As far as i understand what you just said, it shouldn't be treated any different; I don't see how the GROUP BY changes the logic in such a way that mysql doesn't need to return a row with NULL for both fields