it should beselect t.*from yourtable tinner join (select max(Stockdate) [Stockdate],CustomerID from purchasegroup by CustomerID)t1on t1.CustomerID = t.CustomerIDand t1. Stockdate = t.[Stock Date]or 2005 specific solutionSELECT Stockdate,ID,CutomerID FROM(SELECT ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY Stockdate DESC) AS rn,Stockdate,ID,CutomerID FROM purchase)tWHERE rn=1
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/