X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6D5D7475F73 for ; Fri, 21 Feb 2003 16:32:39 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 77340-08 for ; Fri, 21 Feb 2003 16:32:28 -0500 (EST) Received: from utahisp.com (cyber-wire.com [66.239.12.3]) by postgresql.org (Postfix) with ESMTP id E3A2E475F81 for ; Fri, 21 Feb 2003 15:54:52 -0500 (EST) Received: from chad [63.230.8.76] by utahisp.com (SMTPD32-7.14) id A1BF1E4603A4; Fri, 21 Feb 2003 13:53:19 -0700 Message-ID: <053901c2d9eb$0cd85000$32021aac@chad> From: "Chad Thompson" To: "Dan Langille" Cc: References: <3E5649A9.26494.1F008FD6@localhost> Subject: Re: 7.3 "group by" issue Date: Fri, 21 Feb 2003 13:51:35 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for spam. X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/490 X-Sequence-Number: 11888 > 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