X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9DEC753FBD for ; Fri, 15 Apr 2005 10:41:45 -0300 (ADT) 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 10054-09 for ; Fri, 15 Apr 2005 13:41:44 +0000 (GMT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id 4133853FB3 for ; Fri, 15 Apr 2005 10:41:42 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 4.42) id 1DMR4q-0006Bc-Dd; Fri, 15 Apr 2005 13:41:44 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 8FC8417947; Fri, 15 Apr 2005 14:41:42 +0100 (BST) Message-ID: <425FC495.9050203@archonet.com> Date: Fri, 15 Apr 2005 14:41:41 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "GIROIRE, Nicolas (COFRAMI)" Cc: Alex , pgsql-general@postgresql.org Subject: Re: SQL Question References: <5C40CD1E4697424ABDE3AC57CF1B22C62772B0@FR0-MAILMB20.res.airbus.corp> In-Reply-To: <5C40CD1E4697424ABDE3AC57CF1B22C62772B0@FR0-MAILMB20.res.airbus.corp> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/660 X-Sequence-Number: 76573 GIROIRE, Nicolas (COFRAMI) wrote: > For the first request (How can i select only the newest record for each ProdId ?), you can do : > > select * from test."tableProd" u > where u."LastUpdate" = (select max(t."LastUpdate") > from test."tableProd" t > where u."ProdId" = t."ProdId") Although this only guarantees one row if LastUpdate is unique for every ProdId. -- Richard Huxton Archonet Ltd