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 407E55377C for ; Fri, 15 Apr 2005 09:17:09 -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 85604-03 for ; Fri, 15 Apr 2005 12:17:03 +0000 (GMT) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id 65FA0535CA for ; Fri, 15 Apr 2005 09:17:02 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DMPgV-0006uB-Em for pgsql-general@postgresql.org; Fri, 15 Apr 2005 14:12:31 +0200 Received: from gateway.mgm-edv.de ([212.18.1.110]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2005 14:12:31 +0200 Received: from spam_eater by gateway.mgm-edv.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2005 14:12:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Thomas Kellerer Subject: Re: SQL Question Date: Fri, 15 Apr 2005 14:15:00 +0200 Lines: 27 Message-ID: References: <425FAC67.2050203@meerkatsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: gateway.mgm-edv.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; rv:1.7.6) Gecko/20050319 Mnenhy/0.6.0.104 X-Accept-Language: de, de-at, en-us, en In-Reply-To: <425FAC67.2050203@meerkatsoft.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200504/657 X-Sequence-Number: 76570 On 15.04.2005 13:58 Alex wrote: > Hi, > > i have a table > > ProdId | LastUpdate > -------+------------ > 100 | 2005-04-01 > 100 | 2005-03-01 > 100 | 2005-02-01 > 200 | 2005-04-01 > 200 | 2005-03-01 > 200 | 2005-02-01 > > - How can i select only the newest record for each ProdId ? > > 100 | 2005-04-01 > 200 | 2005-04-01 > SELECT prodid, lastupdate FROM produpdate p1 WHERE lastupdate = (SELECT MAX (lastupdate) FROM produpdate p2 WHERE p2.prodid = p1.prodid) Thomas