Getting List of Duplicate Rows with Unique Multiple Columns - LINQ

How can I implement this? Preferably in LINQ if possible

I have a Driver_DT and it has five columns (UID, Name, Gender, Age, and Sponsor). If a row has a duplicate value of UID, Name, Gender, and Age from other row(s) then it will be added on DuplicateList_DT.



As you noticed, 789D Hamilton has a duplicate but they have different age so it will not be added to DuplicateList_DT.


Also, if you noticed 123A Verstappen has duplicates (3 rows in total) but the other one has a different value of Gender and it is NOT added on the DuplicateList_DT while the other duplicate row has a different value of Sponsor but it is added on the DuplicateList_DT


UID and Name and Gender and Age should have same value to other row(s) to be added on DuplicateList_DT.

How can I implement this? Preferably in LINQ if possible

try this one

1 Like

Hi @anthonyjr

kindly refer below sample hope this helps
FindDuplicates.xaml (8.3 KB)

considering an example of your reference


1 Like

give a try at:

(From d in dtData.AsEnumerable
Let sk = String.Join("_",{“UID”,“Name”,“Gender”,“Age”}.Select(Function (x) d(x).toString.Trim))
Group d by k=sk into grp = Group
Where grp.Count > 1
From g in grp
Order by dtData.Rows.IndexOf(g)
Select r=g).CopyToDataTable


Thank you sir @ppr , your solutions are straight-forward and neat as always! I’m learning so much from you, sir!

Thank you sir @nikhil.girish and @saurabhB for the solutions too!

1 Like

Happy Learning @anthonyjr

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