X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9932F3A3EF1 for ; Mon, 25 Oct 2004 12:42:57 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50403-04 for ; Mon, 25 Oct 2004 11:42:50 +0000 (GMT) Received: from pd2mo3so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net [24.71.223.10]) by svr1.postgresql.org (Postfix) with ESMTP id EF7B93A3E67 for ; Mon, 25 Oct 2004 12:42:51 +0100 (BST) Received: from pd3mr3so.prod.shaw.ca (pd3mr3so-qfe3.prod.shaw.ca [10.0.141.179]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0I65009781UYDGD0@l-daemon> for pgsql-sql@postgresql.org; Mon, 25 Oct 2004 05:42:35 -0600 (MDT) Received: from pn2ml2so.prod.shaw.ca ([10.0.121.146]) by pd3mr3so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0I650023G1UY0TF0@pd3mr3so.prod.shaw.ca> for pgsql-sql@postgresql.org; Mon, 25 Oct 2004 05:42:34 -0600 (MDT) Received: from S0106000d612da09e.cg.shawcable.net (S0106000d612da09e.cg.shawcable.net [68.144.50.248]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003)) with ESMTP id <0I6500FME1UY7B@l-daemon> for pgsql-sql@postgresql.org; Mon, 25 Oct 2004 05:42:34 -0600 (MDT) Date: Mon, 25 Oct 2004 05:44:06 -0600 From: "Andrew J. Kopciuch" Subject: Re: sql In-reply-to: To: Mike Rylander Cc: pgsql-sql@postgresql.org Reply-To: akopciuch@bddf.ca Message-id: <200410250544.06403.akopciuch@bddf.ca> Organization: BDDF Developments Inc. MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-transfer-encoding: 7bit Content-disposition: inline References: <013901c4ba6a$8771d320$7202a8c0@aaa> User-Agent: KMail/1.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.2 tagged_above=0.0 required=5.0 tests=FAKE_HELO_SHAW_CA, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200410/170 X-Sequence-Number: 19273 On Monday 25 October 2004 05:20, Mike Rylander wrote: > SELECT * FROM temp50 GROUP BY gc ORDER BY ora DESC; You can not have have expressions (columns etc.) in the SELECT list that are either not in a GROUP BY clause, or used in an aggregate function when you use GROUP BY in the statement. By saying SELECT *, means you would have to GROUP BY gc, co, data, ora ... That isn't going to do what he wants. And the SQL you stated should give you an error: ERROR: column "temp50.co" must appear in the GROUP BY clause or be used in an aggregate function What he wants to do is use DISTINCT ON: SELECT DISTINCT ON (gc) gc, co, data, ora FROM temp50 ORDER BY gc, ora DESC; Andy