Why do I need to explicitly specify all columns in a SQL "GROUP BY" clause - why not "GROUP BY *"?

Posted by rwmnau on Stack Overflow See other posts from Stack Overflow or by rwmnau
Published on 2010-05-05T22:33:14Z Indexed on 2010/05/05 22:38 UTC
Read the original article Hit count: 237

This has always bothered me - why does the GROUP BY clause in a SQL statement require that I include all non-aggregate columns? These columns should be included by default - a kind of "GROUP BY *" - since I can't even run the query unless they're all included. Every column has to either be an aggregate or be specified in the "GROUP BY", but it seems like anything not aggregated should be automatically grouped.

Maybe it's part of the ANSI-SQL standard, but even so, I don't understand why. Can somebody help me understand the need for this convention?

© Stack Overflow or respective owner

Related posts about sql

Related posts about ansi-sql