If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > argh...date problems

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-04, 13:23
gabby_moore gabby_moore is offline
Registered User
 
Join Date: Jul 2004
Posts: 2
argh...date problems

Hi,

I have a quick SQL query that i'm having problems with. Basically i have a product table and a price history table which have a common product_code field. The price history table contains the history of price changes for all products, so there will be one or more rows in it for each product_code (each having an effective_date field which determines when the price becomes/became effective).

I need to query the price table for a list of products and return one row per product containing the product information and current price information for that product

My level of SQL is pretty basic and i can't figure out how to restrict the rows returned from the price table to just the current prices (i.e. the max effective_date before the current date)
Reply With Quote
  #2 (permalink)  
Old 07-19-04, 14:51
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

In Oracle:
Code:
select * from product_table p, product_hist h
where h.prod_cd = p.prod_cd
   and h.eff_date = (
         select MAX(eff_date) from product_hist d
         where d.prod_cd = p.prod_cd);
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 07-20-04, 09:22
gabby_moore gabby_moore is offline
Registered User
 
Join Date: Jul 2004
Posts: 2
cheers for that
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On