Filter the data of two datatables with primary and foreign key columns in uipath

Hello Community,

I want to get the filtered data based on primary and secondary key from two different tables.
First table key column match with second table key column, then get the merged input of two tables as one row

Input Table Data-1:
image

Input Table Data-2:
image

Expected Result:
image

Thanks,

Hi @kishore_reddy2

Use below query

(From row1 In DT1.AsEnumerable()
            Join row2 In DT2.AsEnumerable() 
            On row1("Key").ToString Equals row2("Key").ToString
            Select MergedDT.Rows.Add(row1("Key"), row1("First Name"), row1("Last Name"), row2("Phone Number"), row2("Location"))
           ).CopyToDataTable()

A screenshot of a "Build Data Table" window displaying columns for Key, First Name, Last Name, Phone Number, and Location, all of which are string types. (Captioned by AI)

Regards,

Hi @kishore_reddy2

You can use the core activity for this case: UiPath.Core.Activities.JoinDatatables

Join Type : Inner

image

Please refer the below xaml for the solution.
JoinDataTables.xaml (14.2 KB)

Hi @kishore_reddy2

LINQ Query is the best optimized possible way to achieve your requirement.
I have provided the working code.

(From rowX In DT1.AsEnumerable()
   Join rowY In DT2.AsEnumerable()
   On rowX.Field(Of String)("Key") Equals rowY.Field(Of String)("Key")
   Select FilteredDT.Rows.Add(rowX.Item("Key"), rowX.Item("First Name"), rowX.item("Last Name"), rowY.Item("Phone Number"), rowY.Item("Location")).CopyToDataTable

Happy coding

Cheers,

@lrtetala

Join datatable would do the job

If you want to remove any extra columsn then use filter datatable and you can remove them

Cheers

Thanks for the solution @batthula.p949 It is working for me .

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