pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Fetch the latest log for each product
2+ messages / 2 participants
[nested] [flat]

* Fetch the latest log for each product
@ 2000-08-17 16:55 Bernie Huang <bernie.huang@ec.gc.ca>
  2000-08-17 17:33 ` Re: Fetch the latest log for each product Jeff Hoffmann <jeff@propertykey.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Bernie Huang @ 2000-08-17 16:55 UTC (permalink / raw)
  To: pgsql-sql; PHP-PGSQL <php-pgsql@linuxports.com>

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

Attachments:

bernie.huang.vcf (text/x-vcard, 314B) download begin:vcard n:Huang;Bernie tel;fax:(604)664-9195 tel;work:(604)664-9172 x-mozilla-html:TRUE org:Environment Canada;Standards and Technology Services adr:;;700-1200 West 73 Ave.;Vancouver;BC;V6P 6H9;Canada version:2.1 email;internet:bernie.huang@ec.gc.ca title:Programmer x-mozilla-cpt:;0 fn:Bernie Huang end:vcard
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: Fetch the latest log for each product
  2000-08-17 16:55 Fetch the latest log for each product Bernie Huang <bernie.huang@ec.gc.ca>
@ 2000-08-17 17:33 ` Jeff Hoffmann <jeff@propertykey.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jeff Hoffmann @ 2000-08-17 17:33 UTC (permalink / raw)
  To: Bernie Huang <bernie.huang@ec.gc.ca>; +Cc: pgsql-sql; PHP-PGSQL <php-pgsql@linuxports.com>

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-08-17 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-08-17 16:55 Fetch the latest log for each product Bernie Huang <bernie.huang@ec.gc.ca>
2000-08-17 17:33 ` Jeff Hoffmann <jeff@propertykey.com>

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