SELECT RO.FirstName FROM (SELECT TOP 10 Event.RO_No,Min(Event.DateTime) AS LastUpdate FROM Event INNER JOIN RO ON Temp.RO_No=RO.RO_No GROUP BY Event.RO_No ORDER BY MIN(Event.Datetime)) Temp INNER JOIN RO ON Temp.RO_No=RO.RO_NoSo, this returns something like this:
Ro_No DateTime 1 2007-12-17 14:41:25.704 3 2007-12-17 14:42:25.704 7 2007-12-17 14:43:25.704 22 2007-12-18 15:41:25.704 23 2007-12-19 16:41:25.704 24 2008-12-20 07:41:25.704 25 2009-12-17 08:41:25.704 46 2009-12-17 05:41:25.704 48 2009-12-18 05:41:25.704 49 2009-12-19 14:41:25.704But, Ro_No, in the Event table appears in multiple records. The reason is that the Event table logs everything when there is a change in the record. So, I have a robot process which processes 10 records at a time. So, in the next loop, it will execute the same SQL again and obtain a new batch of 10 records. However, in that new batch, I may end up with a RO_No that I already processed. In our design, there is only a need to process the last one from the Event table. I do not know if that is possible here, if that would require a derived SQL or else.