Hello all,
I need help with a correlated query. I am trying to join two tables on a key and get a record that is the latest from the other table. Let me try to explain this with an example. I have a cust_sales table with multiple records per customer. I also have promo table that have multiple records per customer. I want to be able to join these two tables and get the "recent" promo date for each sales record.
Here is how the tables are structured. (dates are in mm/dd/yyyy).
Cust_sales
customer_key inv_no invoice_dt
56 inv1 5/15/2010
56 inv2 6/5/2010
56 inv3 8/9/2010
cust_promo
customer_key promo_no promo_dt
56 promo1 5/28/2010
56 promo2 8/1/2010
This is the result I am looking to get.
56 inv1 5/15/2010 promo1 5/28/2010
56 inv2 6/5/2010 promo1 5/28/2010
56 inv3 8/9/2010 promo2 8/1/2010
I tried a correlated query with a maximum date and I am not get this result. Can someone help?
Thanks in anticipation.
arvind.k.
I need help with a correlated query. I am trying to join two tables on a key and get a record that is the latest from the other table. Let me try to explain this with an example. I have a cust_sales table with multiple records per customer. I also have promo table that have multiple records per customer. I want to be able to join these two tables and get the "recent" promo date for each sales record.
Here is how the tables are structured. (dates are in mm/dd/yyyy).
Cust_sales
customer_key inv_no invoice_dt
56 inv1 5/15/2010
56 inv2 6/5/2010
56 inv3 8/9/2010
cust_promo
customer_key promo_no promo_dt
56 promo1 5/28/2010
56 promo2 8/1/2010
This is the result I am looking to get.
56 inv1 5/15/2010 promo1 5/28/2010
56 inv2 6/5/2010 promo1 5/28/2010
56 inv3 8/9/2010 promo2 8/1/2010
I tried a correlated query with a maximum date and I am not get this result. Can someone help?
Thanks in anticipation.
arvind.k.