3 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
This article discusses the proposed SQL syntax "GROUP BY ALL," which streamlines the GROUP BY clause by automatically including non-aggregated columns from the SELECT list. The author highlights its benefits and potential pitfalls, noting that while it reduces redundancy, it may also lead to unintended changes in query behavior. The SQL standardization process for this feature is underway.
If you do, here's more
Making GROUP BY simpler has been a top request in SQL. The existing syntax can be cumbersome, as it requires repeating columns or expressions in the GROUP BY clause, leading to potential errors and confusion. A new feature called GROUP BY ALL aims to streamline this. Implemented by several database systems, this syntax allows users to write `GROUP BY ALL`, which automatically expands to include only non-aggregate columns from the SELECT list. For example, in `SELECT a, avg(b) FROM t1 GROUP BY ALL;`, the query effectively becomes `GROUP BY a`.
While GROUP BY ALL simplifies basic cases, it doesn't eliminate the need for explicit GROUP BY clauses in more complex queries. For instance, if your SELECT statement includes additional columns like `c` and `d`, you still need to define how these relate to your grouping. The current specification leaves ambiguity in these scenarios, requiring the user to clarify their intent. This can lead to potential pitfalls, especially if the SELECT list changes later. Implicit changes in the GROUP BY clause might not align with the user's original intention.
Despite these risks, GROUP BY ALL has gained traction, with Oracle and PostgreSQL already implementing it. The SQL standard working group discussed this feature in 2025, gaining consensus for its inclusion. While it offers a shortcut, caution is advised, especially in complex queries where the implications of grouping may not be immediately clear. Overall, this development reflects ongoing efforts to enhance SQL's usability while balancing precision and flexibility.
Questions about this article
No questions yet.