Re: Fetch the latest log for each product

From: Jeff Hoffmann <jeff(at)propertykey(dot)com>
To: Bernie Huang <bernie(dot)huang(at)ec(dot)gc(dot)ca>
Cc: PGSQL-SQL <pgsql-sql(at)postgresql(dot)org>, PHP-PGSQL <php-pgsql(at)linuxports(dot)com>
Subject: Re: Fetch the latest log for each product
Date: 2000-08-17 17:33:03
Message-ID: 399C21CF.77C26118@propertykey.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Webb Sprague 2000-08-17 18:38:02 Re: Continuous inserts...
Previous Message Bernie Huang 2000-08-17 16:55:35 Fetch the latest log for each product