From: Jeff Hoffmann <jeff@propertykey.com>
To: Bernie Huang <bernie.huang@ec.gc.ca>
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Cc: PHP-PGSQL <php-pgsql@linuxports.com>
Subject: Re: Fetch the latest log for each product
Date: Thu, 17 Aug 2000 12:33:03 -0500
Message-ID: <399C21CF.77C26118@propertykey.com> (raw)
References: <399C1907.ADE41FE7@ec.gc.ca>
Bernie Huang wrote:
>
> Hi,
>
> I bet people have asked this question several times, but oh well, please
> do anwser again. Thanks. =)
>
> I have a product table and a log file.
>
> product_tb
> -----------
> prod_id
> prod_name
> ...
>
> log_tb
> ---------
> log_id
> prod_id
> cust_id
> transact_date
> ...
>
> How do I fetch the latest log for each product according to transaction
> date?
>
> - Bernie
here's how i would do it, i guess.
select p.prod_name, l.prod_id, max(l.transact_date) as
last_transaction
from log_tb l, prod_tb p
where l.prod_id=p.prod_id
group by p.prod_name, l.prod_id;
i think that's what you want, at least...
--
Jeff Hoffmann
PropertyKey.com
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jeff@propertykey.com, bernie.huang@ec.gc.ca, php-pgsql@linuxports.com
Subject: Re: Fetch the latest log for each product
In-Reply-To: <399C21CF.77C26118@propertykey.com>
References: <399C1907.ADE41FE7@ec.gc.ca> <399C21CF.77C26118@propertykey.com>
* 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