Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 9AF771B52349 for ; Wed, 23 May 2012 06:37:49 -0300 (ADT) Received: from iota.marktest.pt ([80.251.174.118] helo=hermes.marktest.pt) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SX80o-0007J5-CA for pgsql-sql@postgresql.org; Wed, 23 May 2012 09:37:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by hermes.marktest.pt (Postfix) with ESMTP id A2CB61A8497; Wed, 23 May 2012 10:37:32 +0100 (WEST) X-Virus-Scanned: amavisd-new at marktest.pt Received: from hermes.marktest.pt ([127.0.0.1]) by localhost (hermes.marktest.pt [127.0.0.1]) (amavisd-new, port 11124) with ESMTP id RwrDHnYe5hiP; Wed, 23 May 2012 10:37:32 +0100 (WEST) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by hermes.marktest.pt (Postfix) with ESMTP id 7A52B1A8495; Wed, 23 May 2012 10:37:32 +0100 (WEST) Message-ID: <53C6FD0FE48B43C0AD419648FDC8D943@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: "Gary Stainburn" , References: <201205231027.39198.gary.stainburn@ringways.co.uk> Subject: Re: left outer join only select newest record Date: Wed, 23 May 2012 10:37:31 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Pg-Spam-Score: 0.4 (/) X-Archive-Number: 201205/64 X-Sequence-Number: 36612 Gary, You describe two tables vehicle stock and tax requests. The former has a one-to-many relationship wit the second one, right? But your query involves stock details and used_diary. What is the relationship of these two new tables to the previous ones? Could you please kindly supply an example of what you have and of the desired output? For me it would be easier... Best, Oliver ----- Original Message ----- From: "Gary Stainburn" To: Sent: Wednesday, May 23, 2012 10:27 AM Subject: [SQL] left outer join only select newest record > Hi folks, > > I know I've seen posts like this before but Google isn't helping today. > > I have two tables, vehicle stock and tax requests. Each vehicle can be > taxed > more than once, but I only want to pull in the most recent tax request - > the > one with the highest ud_id. > > I have the following, which obviously returning multiple records which > then > appears that the same vehicle is in stock multiple times. How can I make > it > so we only show each vehicle once, showing the most recent tax request > details. > > > select * from stock_details s > left outer join used_diary u on s.s_registration = u.ud_registration; > > > -- > Gary Stainburn > Group I.T. Manager > Ringways Garages > http://www.ringways.co.uk > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql