How to get output as unique rows by comparing two columns using LINQ query

Hi,
Can anyone please provide me solution by LINQ query

ColumnA Column B
1234 55 ----- need to process
1234 55 --duplicate(not needed)
1234 55 --duplicate(not needed)
2222 55 ----- need to process
2222 66 ----- need to process
2222 66 -duplicate(not needed)
3333 77 ----- need to process

I want to print first row from duplicates only and unique values by comparing both the columns using LINQ query. Please help me on this.

we can use:

  • remove duplicate rows activity
  • dtResult = dtOrig.DefaultView.ToTable(True)

When there is something special, that we only can handle with a LINQ then we would use a groupby strategy

1 Like

Hi @chanbhasha.p

How about this following expression?

dataTable = dtinput.AsEnumerable()
.GroupBy(Function(i) i.Field(Of String)(“columnWithDuplic”))
.Select(Function(g) g.First)
.CopyToDataTable

Regards
Gokul

1 Like

Hi Gokul. Thanks for the valuable reply.

If I take any of the single column name in the query it is missing some unique values again. I have edited my post in detail. Can you please check once and help me on this please @Gokul001

Hi @chanbhasha.p

Try with is expression

Build a datatable with same format and data → name as dtData
dtResults = dtData.Clone

dtResults = (From dte In dtTable.AsEnumerable
Group dte By col1=dte(0).ToString.Trim, col2=dte(1).ToString.Trim Into Group
Select dtResults.Rows.Add({col1,col2})).CopyToDataTable

1 Like

Hi @chanbhasha.p

Check out this sample XAML file in this thread

1 Like

Thank you @Gokul001

HI @chanbhasha.p

Kindly close this topic by mark as solved it will help for other too.

Regards
Gokul