What is the primary key for this table? Using only the info provided thus far you might be looking for this:declare @table table (ID int, OrderDate datetime, Code int)insert into @table select 11, '10/11/2006', 3 union all select 11, '10/12/2006', 1 union all select 11, '10/13/2006', 2select * from @tableselect t.ID, t.OrderDate, t.Codefrom @table tjoin ( select ID, max(OrderDate) OrderDate from @Table group by ID)don t.ID = d.ID and t.OrderDate = d.OrderDate
* But what would the desired resultset be given this input data: select 11, '10/11/2006', 3 union all select 11, '10/12/2006', 1 union all select 11, '10/13/2006', 2 union all select 11, '10/13/2006', 4
Nathan Skerl