>>SELECT TOP 10 Event.RO_No, >>Min(Event.DateTime) AS LastUpdate, >>min(Ro.FirstName) as FirstName >> FROM Event >>inner join RO on Event.Ro_No = RO.Ro_No >> WHERE Event.Event_DateTime>'SomDate' GROUP BY Event.RO_No >> ORDER BY MIN(Event.Datetime) >>and not exists(select 1 from Event E where E.DateTim < ='SomeDate' and E.Ro_No = RO.Ro_NO)>
select RO.*, E.* from RO inner JOIN (select top (10) Event.RO_NO, min(DateTime) as LastUpdate from Event where DateTime > 'DateValue' and not exists (select 1 from Event E where DateTime <='DateValue' and E.Ro_No = Event.Ro_No) GROUP BY Ro_NO order by MIN(Event.DateTime)) E on RO.RO_NO = E.RO_NO