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 E41813A3B0F for ; Mon, 25 Oct 2004 12:20:27 +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 41709-09 for ; Mon, 25 Oct 2004 11:20:20 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.201]) by svr1.postgresql.org (Postfix) with ESMTP id 561E33A2B23 for ; Mon, 25 Oct 2004 12:20:22 +0100 (BST) Received: by rproxy.gmail.com with SMTP id 77so400873rnk for ; Mon, 25 Oct 2004 04:20:22 -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=swuNHAsWbEp/q6YsOYxzX3ap7PGoKUX82G/86BlvUIQ2eltjgquSj9LM5YxJZQiTtUrYSpGseZ/36kSXnMNZIxchu5HlpUsbQnZPYb0ZN8UdcGC8gNR+bh9raAIkXORvUQ7hLN/23JpuXxzgF6F3L8q21bt1WRj98SP9vXb0u28= Received: by 10.38.15.13 with SMTP id 13mr1038729rno; Mon, 25 Oct 2004 04:20:22 -0700 (PDT) Received: by 10.38.126.17 with HTTP; Mon, 25 Oct 2004 04:20:22 -0700 (PDT) Message-ID: Date: Mon, 25 Oct 2004 07:20:22 -0400 From: Mike Rylander Reply-To: Mike Rylander To: cristivoinicaru Subject: Re: sql Cc: pgsql-sql@postgresql.org In-Reply-To: <013901c4ba6a$8771d320$7202a8c0@aaa> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <013901c4ba6a$8771d320$7202a8c0@aaa> 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/169 X-Sequence-Number: 19272 On Mon, 25 Oct 2004 10:13:37 +0200, cristivoinicaru wrote: > I have a postgres table like this: > > CREATE TABLE "temp50" ( > "gc" character varying(36), > "co" character varying(7), > "data" date, > "ora" smallint > > ); > > It contains the following records: > > 5003707G9G9419 22012BB 10-14-2004 82 > 5003707G9G9419 22012BC 10-14-2004 44 > 5003707G9G9419 22022BB 10-14-2004 82 > 5003707G9G9420 22022BC 10-18-2004 49 > > I'd like the result of the sql interogation to be like this: > > 5003707G9G9419 22012BB 10-14-2004 82 > 5003707G9G9420 22022BC 10-18-2004 49 > > Explanations: > I want like sql interogation to select only one record from each "gc" group > record (who has the same code "gc" (that means that the "gc" field will be > unique key)) with the following two condition: > 1)from each "gc" group of records to select the record who has the value of > "ora" field maxim. > 2)if two ore more record have the same value of the maxim value of the "ora" > to select oly one of them Try: SELECT * FROM temp50 GROUP BY gc ORDER BY ora DESC; --miker > > Thanks! > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend >