Return top 1 row from a datatable filtered by unique values in a specifc column

In this example, columnA must be unique.

ColumnA | ColumnB
1 | a
1 | b
1 | b
2 | a
2 | a
3 | b
3 | c
3 | d

the result has to be

1 a
2 a
3 b

Give a try on YourDataTableVar.AsEnumerable.Distinct(DataRowComparer.Default).CopyToDataTable
to retrieve the Distinct Rows

In your example you should clear 3b is fetched due the ordered occurence and that this has no sideeeffects

With a group by and fetching the first row from each group you will get the result


A demo here
ReturnFirstRowFromGroup.xaml (7.1 KB)


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.