Re: Fetch the latest log for each product - Mailing list pgsql-sql

From Jeff Hoffmann
Subject Re: Fetch the latest log for each product
Date
Msg-id 399C21CF.77C26118@propertykey.com
Whole thread Raw
In response to Fetch the latest log for each product  (Bernie Huang <bernie.huang@ec.gc.ca>)
List 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


pgsql-sql by date:

Previous
From: Bernie Huang
Date:
Subject: Fetch the latest log for each product
Next
From: Webb Sprague
Date:
Subject: Re: Continuous inserts...