Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I group by only one column in a SELECT statement?

397444Jun 30 2003 — edited Jul 5 2003
Hi everyone,

Here is my novice question:

I would like to run a query where I select (display) several columns from my table, yet group (categorize) by one of these columns.

For example:

SELECT A, B, COUNT(A)
FROM TableX
GROUP BY A

I realize now that this is not valid. My first question is why? Doesn't it make sense that you would want to group by only one of the columns? To me, it seems natural that you would most often want to categorize by one attribute, which is why it seems odd that this is not valid. I realize that I can remove column B, but I do want to display that info. I could also change the last statement to GROUP BY A, B to avoid errors, but this will also not display what I am looking for.

In addition to understanding why Oracle is set up this way, I guess I also need to know how I can legally accomplish this query, grouping by A but also displaying the values of B.

Thank you very much for your help!

Holly
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2003
Added on Jun 30 2003
4 comments
1,684 views