pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chad Thompson <chad@weblinkservices.com>
To: Dan Langille <dan@langille.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: 7.3 "group by" issue
Date: Fri, 21 Feb 2003 13:51:35 -0700
Message-ID: <053901c2d9eb$0cd85000$32021aac@chad> (raw)
References: <3E5649A9.26494.1F008FD6@localhost>




> 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




view thread (14+ messages)  latest in thread

Message-ID: <053901c2d9eb$0cd85000$32021aac@chad>
Permalink:  ../053901c2d9eb$0cd85000$32021aac@chad/
Also on:    postgresql.org/message-id/053901c2d9eb$0cd85000$32021aac@chad

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chad@weblinkservices.com, dan@langille.org
  Subject: Re: 7.3 "group by" issue
  In-Reply-To: <053901c2d9eb$0cd85000$32021aac@chad>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox