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 2E7BF3A40F6 for ; Mon, 25 Oct 2004 08:14:18 +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 71029-04 for ; Mon, 25 Oct 2004 07:14:15 +0000 (GMT) Received: from mail.dmhi.ct.ro (dmhi.ct.ro [193.226.151.66]) by svr1.postgresql.org (Postfix) with ESMTP id A7A3F3A40E2 for ; Mon, 25 Oct 2004 08:14:14 +0100 (BST) Received: from aaa ([192.168.2.114]) by mail.dmhi.ct.ro (8.12.8/8.12.8) with SMTP id i9PDGeak009606 for ; Mon, 25 Oct 2004 16:16:40 +0300 Message-ID: <013901c4ba6a$8771d320$7202a8c0@aaa> From: "cristivoinicaru" To: Subject: sql Date: Mon, 25 Oct 2004 10:13:37 +0200 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.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=LINES_OF_YELLING X-Spam-Level: X-Archive-Number: 200410/165 X-Sequence-Number: 19268 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 Thanks!