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 7069D3A40D6 for ; Mon, 25 Oct 2004 14:05:44 +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 74497-09 for ; Mon, 25 Oct 2004 13:05:36 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.194]) by svr1.postgresql.org (Postfix) with ESMTP id D14FC3A40E2 for ; Mon, 25 Oct 2004 14:05:38 +0100 (BST) Received: by rproxy.gmail.com with SMTP id 77so408203rnk for ; Mon, 25 Oct 2004 06:05:39 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=mlLx1L4Lql2tl4Y45+M3dPVEhiIObyQMY7p/24HVIEsaXVfIZDXVsjuITIVSfZq3zTZ/shpyg0t0M3HeZsOAlc8YtRJzv/zaYvbaf6wbXlAcXmp5FIIzxsiA8hrS8WKJtdWCfngCKMZhX9XwO7XC74gZ85Kgn+arpf6I6bMQZZE= Received: by 10.38.82.50 with SMTP id f50mr1067856rnb; Mon, 25 Oct 2004 06:05:39 -0700 (PDT) Received: by 10.38.126.17 with HTTP; Mon, 25 Oct 2004 06:05:39 -0700 (PDT) Message-ID: Date: Mon, 25 Oct 2004 09:05:39 -0400 From: Mike Rylander Reply-To: Mike Rylander To: akopciuch@bddf.ca Subject: Re: sql Cc: pgsql-sql@postgresql.org In-Reply-To: <200410250544.06403.akopciuch@bddf.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <013901c4ba6a$8771d320$7202a8c0@aaa> <200410250544.06403.akopciuch@bddf.ca> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/171 X-Sequence-Number: 19274 On Mon, 25 Oct 2004 05:44:06 -0600, Andrew J. Kopciuch wrote: > 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 ... Doh! Of course. Should have had coffee before writing that ;) > > 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 >