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

Home -> Community -> Usenet -> c.d.o.misc -> Re: GROUP BY Expression

Re: GROUP BY Expression

From: Arjan van Bentem <avbentem_at_DONT-YOU-DAREdds.nl>
Date: Fri, 23 Apr 1999 16:38:46 +0200
Message-ID: <7fq0la$2gc$1@weber.a2000.nl>


Newsworthy wrote
> SELECT *
> FROM Students U, Sessions E, Seminars S
> WHERE S.ID = E.ID AND
> E.SID = U.SID AND
> E.IID = 235
> GROUP BY U.oak_id
> ORDER BY U.NameLast, U.NameFirst

In the group by part you should mention ALL columns you select, except for group by expressions like min(..), max(..), count(..) etc. For example:

    select age, sex, count(*)
    from students
    group by age, sex;

would get you something like

    18 F 15
    18 M 20
    19 F 22
    19 M 26
    20 F 4
    20 M 8

Now, if you would not group by sex, how should Oracle present the results? Something like:

    18    ?    35
    19    ?    48
    20    ?    12

Oracle cannot do this, so really each column you select should be mentioned.

However, in your case you do not use any group by expression at all, so why bother using group by? Simply

    order by U.oak_id, U.NameLast, U.NameFirst

should do.

Arjan. Received on Fri Apr 23 1999 - 09:38:46 CDT

Original text of this message

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