Re: 7.3 "group by" issue

From: "Chad Thompson" <chad(at)weblinkservices(dot)com>
To: "Dan Langille" <dan(at)langille(dot)org>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: 7.3 "group by" issue
Date: 2003-02-21 20:51:35
Message-ID: 053901c2d9eb$0cd85000$32021aac@chad
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On 21 Feb 2003 at 13:30, Chad Thompson wrote:
>
> > The same applies to group by... Sorry for the confusion.
> >
> > If the column is not in the select section of the statement, it cant
group
> > by it.
> > Try this.
> >
> > SELECT element_id as wle_element_id, COUNT(watch_list_id)
> > FROM watch_list JOIN watch_list_element
> > ON watch_list.id = watch_list_element.watch_list_id
> > WHERE
> > watch_list.user_id = 1
> > GROUP BY wle_element_id
>
> Yes, that works. But so do these.
>
> SELECT watch_list_element.element_id as wle_element_id,
> COUNT(watch_list_id)
> FROM watch_list JOIN watch_list_element
> ON watch_list.id = watch_list_element.watch_list_id
> WHERE
> watch_list.user_id = 1
> GROUP BY watch_list_element.element_id
>
>
> SELECT element_id as wle_element_id, COUNT(watch_list_id)
> FROM watch_list JOIN watch_list_element
> ON watch_list.id = watch_list_element.watch_list_id
> WHERE
> watch_list.user_id = 1
> GROUP BY element_id
>
> The original situation which did not work is:
>
> SELECT watch_list_element.element_id as wle_element_id,
> COUNT(watch_list_id)
> FROM watch_list JOIN watch_list_element
> ON watch_list.id = watch_list_element.watch_list_id
> WHERE
> watch_list.user_id = 1
> GROUP BY element_id
>
> My question: why should it not work? It's referring to the same
> column as the previous two examples which do work.
> --

I see the distinction you are making.

Maybe Tom or Josh could throw out a better answer, but I think that youve
called it one thing in your select and tried to group by it using a
syntaticly different name.

Any one have any other ideas?

Chad

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Matthew Nuzum 2003-02-21 22:33:20 join gone awry
Previous Message Dan Langille 2003-02-21 20:45:45 Re: 7.3 "group by" issue