Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Retrieving max row

Author  Topic 

Shumaila
Starting Member

21 Posts

Posted - 2001-11-05 : 07:54:28
Hi,

I have a table which have cust_id and product_id and order date.
Customer 1 can order product 1 many times only dateandtime would be different. I need to get the latest order for each (customer, product) combination
C1 ,p1 could have many rows i need only latest one. and same is true for c1, p2.... c2, p1...


I can't get the query straight.
So far i have come up with

select * from Order join
(select Customer_ID, Product_id , max(datetimestamp) as max_date
from Order
group by Customer_ID, Product_id) A
on Order.Customer_id = A.Customer_id and Order.Product_id = A.Product_id


This join query is giving all the records instead of the latest order

   

- Advertisement -