Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1A115633D95 for ; Sat, 26 Sep 2009 17:15:47 -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 96757-10 for ; Sat, 26 Sep 2009 20:15:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.emproshunts.com (mail.emproshunts.com [66.64.191.19]) by mail.postgresql.org (Postfix) with ESMTP id 764DA633426 for ; Sat, 26 Sep 2009 17:15:39 -0300 (ADT) Received: from [192.168.1.45] by mail.emproshunts.com (GMS 15.02.3689/KX5895.00.ca608199) with ESMTP id cjislaaa for pgsql-sql@postgresql.org; Sat, 26 Sep 2009 16:16:52 -0400 Message-ID: <4ABE7669.50001@emproshunts.com> Date: Sat, 26 Sep 2009 16:15:37 -0400 From: justin User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: David W Noon , pgsql-sql@postgresql.org Subject: Re: simple (?) join References: <200909241616.36933.gary.stainburn@ringways.co.uk> <20090924194629.44bc236f@dwnoon.ntlworld.com> <4ABBD34B.9080600@emproshunts.com> <20090924222106.23a5c1f3@dwnoon.ntlworld.com> <4ABE6360.20205@emproshunts.com> <20090926205349.5fa284f1@dwnoon.ntlworld.com> In-Reply-To: <20090926205349.5fa284f1@dwnoon.ntlworld.com> Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.1.45] X-DNSBL: 0 X-AntiSpam: Checked for restricted content by Gordano's AntiSpam Software X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.273 tagged_above=-10 required=5 tests=BAYES_40=-0.185, HTML_MESSAGE=0.001, MIME_HTML_ONLY=1.457 X-Spam-Level: * X-Archive-Number: 200909/128 X-Sequence-Number: 33193 David W Noon wrote:
On Sat, 26 Sep 2009 14:54:24 -0400, justin wrote about Re: [SQL] simple
(?) join:

[snip]
  
Quoting Gary
"How can I select all from orders and the last (latest) entry from the 
orders_log?"
    

In that case, a simple Cartesian product will do:

SELECT o.*, maxi.ts
FROM orders AS o,
(SELECT MAX(ol_timestamp) AS ts FROM orders_log) AS maxi;

Since the cardinality of the subquery "maxi" is 1, it will give a result
set with cardinality of the complete orders table.

I don't understand why anybody would want to do that. [De gustibus ... ]
  

Guessing here

 Answer to return the last time someone either viewed or edited the order.

This is a very common audit requirement to track who what, when and why something happened.