Re: Why is "group by" obligatory in SQL?

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Thu, 23 Jul 2009 10:20:49 -0300
Message-ID: <4a6863b6$0$23755$9a566e8b_at_news.aliant.net>


Hans Mayr wrote:

> Hello,
>
> I still don't know if there is a better group to post general
> questions about SQL and the background. So I hope nobody minds ;-)
>
> My question is: Why do you have to state the GROUP BY explicitly in
> SQL? Why isn't it enough to write "select a_field, sum(b_field) from
> c_table;"? What additional value is generated by "group by a_field"?
>
> Thanks and best,
>
> Hans

Because SQL made the mistake of allowing duplicate rows and not requiring candidate keys, in SQL, one could group by addtional columns:

select a_field, sum(b_field)
from c_table
group by a_field, d_field; Received on Thu Jul 23 2009 - 15:20:49 CEST

Original text of this message