From your example, it seems like you want to keep the highest (latest) time rather than the lowest (earliest) time. The code below will pick the latest time.select Emp_Code,Name,Date from(select *, row_number() over (partition by Emp_Code, dateadd(dd,datediff(dd,0,Date),0) order by Date desc) as rnfrom Employees) s where rn = 1
This will work only if you are on SQL 2005 or later.If you want to pick the earliest time, change the "order by Date desc" to "order by Date asc".