Disticnt row values of particular row in to other datatable

Hi ,

I need a help to get a distinct values from two datatables dt1 & dt2 the output should be in dt3.

DT1
Name
kkk
hhhh
pppp
rrrrr
hhj

DT2
Name
kkk
hhhh
pppp

Output DT3

Name
kkk
hhhh
pppp

Hi @karthik_kulkarni1

Try this:

  1. Initialize DT3 (Empty DataTable).
  2. Merge DT1 into DT3 (PreserveSchema, Uncheck AddHeaders).
  3. Merge DT2 into DT3 (PreserveSchema, Uncheck AddHeaders).
  4. Remove Duplicate Rows from DT3.
  5. DT3 now contains distinct values from DT1 and DT2.

Hope it helps!!

@karthik_kulkarni1

to get common values

dt1.AsEnumerable.intersect(dt2.AsEnumerable,system.Data.DataRowComparer.Default).CopyToDataTable

dt1.AsEnumerable.Except(dt2.AsEnumerable,system.Data.DataRowComparer.Default).CopyToDataTable

try this to get distinct

I have 3 others columns in DT1 and in DT2 only one column I need condition based on specific column @Parvathy @Shiva_Nikhil

@karthik_kulkarni1

Dt1.AsEnumerable().Where(Function(row) Dt2.AsEnumerable().Any(Function(x)
x(“ColumnName”).ToString=row(“ColumnName”).ToString)).CopyToDataTable

to get matches values of both datatables comparing one particular column

@karthik_kulkarni1

dt3 = (From row In dt1.AsEnumerable()
Select row
).Union(
From row In dt2.AsEnumerable()
Select row
).CopyToDataTable()

Your solution is working but it is failing when no value matches and getting error as “source contains no datarows”

in DT1 & DT2 if no value matches it is failing

we could shorten to

dt1.AsEnumerable().Union(dt2.AsEnumerable()).CopyToDataTable

Handling empty results we do:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

But we do feel, that a different result is expected which we will not produce with the union

Specific column will not work here I hope because in my scenario (DT1 has three columns and DT2 has only one )

yes, as we mentioned: