This works:Select a.Location, a.Item, b.Lastdate, a.Stockfrom table ajoin ( select Location, Item, max([date]) as Lastdate from @ group by Location, Item) bon a.Location = b.Location and a.Item = b.Item and a.[Date] = b.LastDate
as does this:select Location, Item, [Date] as [Last Date], Stockfrom ( select Location, Item, [Date], Stock , max([date]) over(partition by Location, Item) as Lastdate from table) _
You'll need to test them both to figure out which one performs best for you