How to remove duplicate based on two column

Hi Team,

I need to remove duplicate based on two column, if YY no column is duplicate but XX no column unique means I don’t want to delete, both column (YY no and XX no) duplicate than only remove duplicate , I couldn’t able to do so please help me anyone for this.

Input
image

Expected Output:
image

Regards,
Raja G

Hi @Raja.G,

You can use this assign.

(
From row In yourDatatableVariable
Group row By
k1 = row(“XX no”).ToString.Trim,
k2 = row(“YY no”).ToString.Trim
Into grp = Group
Select grp(0)
).CopyToDataTable

Regards.
Ömer

1 Like

in addition to Ömer we can do following:
grafik
dtResult =

(From d In dtData2.AsEnumerable
Group d By  k1=d(0).toString.Trim,  k2=d(2).toString.Trim Into grp=Group
Where grp.Count  = 1
Select r = grp.First()).CopyToDataTable

Here we used the 2 cols for the grouping and fetching only the rows when group.count = 1
So we ommited 880, 88887779 - Kannan, Kala

But we do feel that your requirement is different. Maybe you can recheck with some other samples

Also have a look here (Non-LINQ, LINQ Approaches described)

1 Like

Hi @omer.ozturk , @ppr ,

Thanks guys working fine

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