Received: from grunt.candata.com (gateway.candata.com [204.225.91.106]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eBDM8kX48707 for ; Wed, 13 Dec 2000 17:08:46 -0500 (EST) (envelope-from steve@candata.com) Received: from candata.com (steve@grunt.candata.com [192.168.1.15]) by grunt.candata.com (8.9.3/8.9.3) with ESMTP id RAA18548; Wed, 13 Dec 2000 17:09:15 -0500 Message-ID: <3A37F38A.D52497C0@candata.com> Date: Wed, 13 Dec 2000 17:09:14 -0500 From: Steve Meynell Organization: CanData X-Mailer: Mozilla 4.74 [en] (X11; U; Linux 2.2.5-15 i586) X-Accept-Language: en MIME-Version: 1.0 To: Joel Burton CC: pgsql-sql@postgresql.org Subject: Re: Selecting Most Recent Row References: <3A37A5FF.26823.13E1C98@localhost> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200012/114 X-Sequence-Number: 448 Joel, Thank you very much. I gave that a try and it worked perfectly. It definately was the distinct keyword I was missing. Thanks Again, Steve Joel Burton wrote: > > Will DateStamp being the date of insertion? If so, is it that you want > the record for the most recent (largest) datestamp for each > batch_number? > > something like > > SELECT DISTINCT ON (batch_number) unique_key, datestamp, > batch_number, instructions FROM widgets ORDER BY batch_number, > datestamp desc; > > (sort by batch then by date (last first) and show the first (aka > 'distinct') row, considering only the batch_number for distinctness)