I want to remove duplicate rows from datatable by comparing single column

I need to remove duplicate rows which is highlighted by comparing Column Name [claim No] from data table. Please help me to handle this.

@qbss, You can use “Remove Duplicate Rows” activity

1 Like

Use group by and select first element


1 Like

It compare all the columns in rows. I need to remove duplicate rows based [Claim No] Column alone

Please update the query.

@qbss, In that case, you have to loop through the table and use “Remove Data Row” activity within.

The following thread might help you to build logic around how to loop through and compare it with the previous value and delete row if you find it as duplicate.

1 Like

(From p In Datatable_Name.AsEnumerable() Group By id=p(“Column_Name”).ToString into group Select group(0)).CopyToDatatable


It also return the one entry of duplicate record. In my scenario i want to remove all the duplicate records.

newDatatable = oldDatatable.DefaultView.ToTable(true, “Claim_No”);
If you want to remove duplicate rows based on multiple columns, specify the column names separated by ‘,’
newDatatable = oldDatatable.DefaultView.ToTable(true, “Patient_Responsibility”);

Hope this helps!


My Input:

My Output should be like below,

Please help me.

Use this Query
newDatatable = oldDatatable.DefaultView.ToTable(true, “Claim_No”)

Already tried, this not working. It return one entry of duplicate rows.

@qbss, you can do something like this:




  1. Lets consider your table as, dtTable

  2. First try getting all the duplicate rows,
    dtDuplicateTable = dtTable.AsEnumerable().GroupBy(Function(dr) dr.Field(Of String)(“Claim_No”)).Where(Function(g) g.Count() > 1).SelectMany(Function(g) g).ToList().CopyToDataTable

  3. Now compare the original table with duplicate table and exclude the duplicate rows from original table,
    dtFinalTable = dtTable.AsEnumerable().Except(dtDuplicateTable.AsEnumerable, DataRowComparer.Default).CopyToDataTable

P.S: Check for record existence before converting as CopyToDataTable while doing complete implementation. Otherwise, if there are no records found, the statement will through exception.

Let me know if this works for you.


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