Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Why using "Group By"

Re: Why using "Group By"

From: Mikito Harakiri <mikharakiri_at_ywho.com>
Date: Thu, 13 Mar 2003 13:18:53 -0800
Message-ID: <JG6ca.18$wV5.85@news.oracle.com>

"oferbu" <junkbu_at_hotmail.com> wrote in message news:b9b409f2.0303130207.42f8ab91_at_posting.google.com...
> Hello All,
>
> This is a theoretical question. Why do I need to add the "Group By" in
> the following SQL:
>
> SELECT
> CUSTOMER_CITY, COUNT(*)
> FROM
> CUSTOMER_TABLE
>
> Isn't it clear that I want to get the number of rows per city, so why
> is it necessary to add:
>
> GROUP BY
> CUSTOMER_CITY
>
> I mean to say that those added lines didn't give more information, and
> any resonable person (or a good sql parser...) could have understand
> what I really want at the first sql.

One more reason: you can omit aggregate and emulate "distinct" like this

select empno, name, sal, deptno from emp group by empno, name, sal, deptno

Therefore, either "distinct" is redundant as we can express it via "group by" or, alternatively, "group by" is redundant and can be expressed via corellated scalar subquery in the select clause, but we need "distinct" then. I wonder what theoretical reason behind this fact is. Received on Thu Mar 13 2003 - 15:18:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US