I have a table TableA with two columns: MyName nvarchar(100) and MyDateTime DateTime. There can be multiple records for each MyName that have different DateTimes. I am trying to return a record set that contains each value of MyName from the table, with the earliest MyDateTime for each one.
This works to return the distinct MyNames:
SELECT DISTINCT([MyName]) FROM TableA
I have tried different UNION statements but all my attempts are thrown off by the DISTINCT() keyword. The following query, for instance, finds all of the times, not just the minimum value for each:
SELECT DISTINCT([MyName]), [MyDateTime] FROM TableA
Struggling to come up with correct SQL syntax to accomplish this. Any help, please?
1 Answer