Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 5A554632D23 for ; Mon, 28 Sep 2009 10:44:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 20509-01 for ; Mon, 28 Sep 2009 13:43:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.ringways.co.uk (hub.ringways.co.uk [77.86.27.30]) by mail.postgresql.org (Postfix) with ESMTP id 435A8632345 for ; Mon, 28 Sep 2009 10:43:58 -0300 (ADT) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1MsGQd-00007D-DN; Mon, 28 Sep 2009 14:38:12 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: Jim Subject: Re: simple (?) join Date: Mon, 28 Sep 2009 14:43:53 +0100 User-Agent: KMail/1.9.10 References: <200909241616.36933.gary.stainburn@ringways.co.uk> <200909281202.20768.gary.stainburn@ringways.co.uk> In-Reply-To: Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200909281443.53367.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200909/132 X-Sequence-Number: 33197 On Monday 28 September 2009 13:30:32 you wrote: > SELECT o.*, ol.* > FROM orders o > LEFT JOIN ( > SELECT ol.o_id, MAX(ol_timestamp) AS maxts > FROM orders_log ol > GROUP BY 1 > ) max_olt > ON max_olt.o_id=o.o_id > LEFT JOIN orders_log ol > ON ol.o_id=o.o_id > AND ol.ol_timestamp=max_olt.maxts > ; Cheers Jim, That worked. Gary -- Gary Stainburn Gary's Haircut 700 Please visit http://www.justgiving.com/Gary-Stainburn/ to help me raise money for Cancer Research - in return I'll have my head shaved