Suppose I have the following SQL server table:
I would like the following result, wherein there is only one record per ID and it is the one with the lowest value for field A, but Fields B and C are also included, like so:
How would I accomplish this? Given that group by in sql server disallows the inclusion of fields that are not in the group by clause. I tried a couple things but they all had the same result with an incorrect number of results, the most quintessential being the following:
SELECT a.*
FROM MyTable as a
join (SELECT [ID], min ([Field A]) as [Field A] FROM MyTable group by [ID]) as b on a.ID = b.id
where a.Field A = b.Field A and a.ID = b.ID
order by OBJECTID
From my understanding the number of results of this should not exceed the number of distinct IDs yet it did, so it must not be doing what I thought it would.
Any help would be much appreciated. Thank you.