pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: simple (?) join
Date: Mon, 28 Sep 2009 12:02:20 +0100
Message-ID: <200909281202.20768.gary.stainburn@ringways.co.uk> (raw)
In-Reply-To: <4ABE7669.50001@emproshunts.com>
References: <200909241616.36933.gary.stainburn@ringways.co.uk>
	<20090926205349.5fa284f1@dwnoon.ntlworld.com>
	<4ABE7669.50001@emproshunts.com>

On Saturday 26 September 2009 21:15:37 justin wrote:
>  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. 

For some reason the reply I sent on Friday didn't get through.
What I need is all of the order record and all of the latest log entry 
returning as a join. Specifically I want for each order the most recent log 
entry timestamp and it's associated user - i.e. who made the the last log 
entry and when.

I suppose I'm asking how I would do the sub-query to pull the most recent log 
entry per order.


-- 
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
 



view thread (25+ messages)  latest in thread

Message-ID: <200909281202.20768.gary.stainburn@ringways.co.uk>
Permalink:  ../200909281202.20768.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/200909281202.20768.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: simple (?) join
  In-Reply-To: <200909281202.20768.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox