Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: GROUP BY Expression
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
![]() |
![]() |