Get only unique rows from Datatable based on single Column Values

I need to get only the unique rows from a data table based on values from a single column.

However, I do not just want the single iteration and the other duplicates stripped out.
I require ALL rows which are duplicates to be removed and for the data table to only include rows which are completely unique.

Hi,

Can you share example of your input and expected output?

If you need to remove all the rows which has same value in some column, the following will work.

newDt = dt.AsEnumerable.GroupBy(Function(r) r("Column1").ToString).Where(Function(g) g.Count=1).Select(Function(g) g.First()).CopyToDataTable()

Regards,

1 Like

Hello @elliot.barling
Assuming Input and output

Try this

From row In dt.AsEnumerable()
Group row By key = row.Field(Of String)(“Name”) Into grp = Group Where
grp.Count() = 1
From r In grp
Select r).CopyToDataTable()

Regards,
Rajesh Rane

Hi @elliot.barling

Pls check the below thread:

Happy Automation