Finding duplicate items in a datatable

Is there a way we can find out duplicate items of a column in datatable without looping it for each row but can be fetched as a list or array or datatable itself w=using one-liner function? Can we use dtTable.Dataview for this ? Any inputs would be appreciated. Thanks!


Hi, check this below :point_down:

@mz3bel @arivu96

Thank you for pointing me there. But I am getting this exception with the above expression. Am I missing something here?

Datatble testDt= (From p in dt.Select() where( From q in dt.Select() where String.Join(",",q.ItemArray).Equals(String.Join(",",p.ItemArray)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Assign: The source contains no DataRows.

Dim allDuplicates As List(Of String) = dt.AsEnumerable().GroupBy([Function](dr), dr.Field(Of String)("VMDList")).Where([Function](g), g.Count() > 1).SelectMany([Function](g), g).ToList()

@bcorrea Thanks! This will fetch duplicates of multiple records under column “VMDList” but how do I change this to filter duplicates of just one record?

I dont understand what you ask, do you mean records that appear only 2 times? Or do you want to find duplicates of a particular value only?

Please refer

I want to find duplicates of a particular value only.

If we want to find the array of duplicate values from a particular column of a table then
In a assign activity

List_variable = yourdatatablename.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”).ToString).ToArray().GroupBy(Function(x) x).Where(Function(y) y.Count() > 1).ToList()
Cheers @Sachingoudar

would be easier to just filter for it then…

@Palaniyappan Thanks! I think its just another form of above expression? My Q here is how to filter duplicate records of an employee from an Employee datable where EmployeId= 1.

1 Like