In your case you just need to get MAX(Event.DateTime) as LastDateTime
SELECT Event.RO_No,max(Event.DateTime) as LastDateTime FROM Event GROUP BY Event.RO_No
Take also look at
Including an Aggregated Column's Related ValuesIncluding an Aggregated Column's Related Values - Part 2>If I have the following SQL, I can group by the related field:
>
>
>SELECT Event.RO_No FROM Event GROUP BY Event.RO_No
>
>
>Now, I need to add a secondary field in regards to the grouping. Basically, RO_No is a foreign key. So, there are multiple occurences of it in the Event table. So, in the result, I need to grab a datetime field. If I do this, it will not work.
>
>
>SELECT Event.RO_No,Event.DateTime FROM Event GROUP BY Event.RO_No
>
>
>The reason is that Event.DateTime is not included in the group. But, in this case, I cannot include it in the group as it will take all the records from the table. As RO_No is not my primary key and there are multiple occurences of it in the table, I cannot use the first SQL and subset that into another SQL to get the related additional needed fields. How to adjust that to fit the requirements?
If it's not broken, fix it until it is.
My Blog