maybe something like this:declare @t table (Primarykey varchar(40), LastOnDuty varchar(40))insert into @t (Primarykey, LastOnDuty) values('CA104','27/02/2015-08:00:00 27/02/2015 16:30'),('CA104','27/02/2015-20:00:00 27/02/2015 23:07'),('CA126','27/02/2015-07:00:00 27/02/2015 17:36'),('CA171','27/02/2015-16:00:00 27/02/2015 23:28'),('CA174','27/02/2015-07:00:00 27/02/2015 19:14'),('CA174','27/02/2015-19:00:00 27/02/2015 04:07'),('CA262','27/02/2015-06:30:00 27/02/2015 17:45'),('CA262','27/02/2015-18:30:00 27/02/2015 23:01'),('CA285','27/02/2015-19:00:00 27/02/2015 23:07'),('CA332','27/02/2015-18:30:00 27/02/2015 23:51'),('CA361','27/02/2015-07:00:00 27/02/2015 17:46'),('CA412','27/02/2015-07:00:00 27/02/2015 19:03'),('CA412','27/02/2015-19:00:00 27/02/2015 22:58'),('CA461','27/02/2015-07:00:00 27/02/2015 19:16'),('CR296','27/02/2015-08:00:00 27/02/2015 15:31'),('CR316','27/02/2015-07:00:00 27/02/2015 19:19'),('CR317','27/02/2015-07:00:00 27/02/2015 19:58'),('CR317','27/02/2015-19:00:00 27/02/2015 01:53'),('CR427','27/02/2015-08:00:00 27/02/2015 19:47'),('CR428','27/02/2015-18:00:00 27/02/2015 18:44'),('CR505','27/02/2015-17:30:00 27/02/2015 22:55'),('NA217','27/02/2015-20:00:00 27/02/2015 06:51'),('NA235','27/02/2015-20:00:00 27/02/2015 23:42'),('NA236','27/02/2015-10:00:00 27/02/2015 21:07'),('NA240','27/02/2015-19:00:00 27/02/2015 23:52'),('NA251','27/02/2015-07:00:00 27/02/2015 19:52'),('NA261','27/02/2015-20:00:00 27/02/2015 23:15'),('NA292','27/02/2015-07:00:00 27/02/2015 16:38'),('NA302','27/02/2015-19:30:00 27/02/2015 23:52'),('NA322','27/02/2015-12:00:00 27/02/2015 21:43')delete from tfrom @t tcross apply ( select Row_Number() OVER (Partition by Primarykey Order by LastOnDuty Desc ) as RowNo from @t t1 where t.Primarykey = t1.Primarykey) subqwhere subq.RowNo > 1select * from @torder by Primarykey