Re: Problem with the group statement...

From: Larry Coon <>
Date: Mon, 15 Jul 2002 15:45:10 -0700
Message-ID: <>

Volker Hetzer wrote:

> Hi!
> I have trouble understanding the group statement. Here is
> a small example:
> create temporary table x (a int, b int);
> insert into x values(1,1);
> insert into x values(1,2);
> insert into x values(1,3);
> insert into x values(2,1);
> insert into x values(2,2);
> insert into x values(2,3);
> insert into x values(3,1);
> insert into x values(3,2);
> insert into x values(3,3);
> select * from x group by a;
> Now, this gives me:
> a b
> 1 1
> 2 1
> 3 1
> However, I had expected it to give the whole table.

Typically, when you use GROUP BY every item in the list of columns either appears in the GROUP BY clause or is an aggregate function. (I said "typically" because I thought that was a rule, but since it obviously works for you, I'm open to the possibility that this is something in the standard about which I am not aware.)

At the very least, this is not a canonical use of the GROUP BY. What, semantically, are you trying to accomplish with your query?

Larry Coon
University of California
and Received on Tue Jul 16 2002 - 00:45:10 CEST

Original text of this message