3

I can find lots of information about merging two DataTables and dropping duplicate rows, but I need the opposite.

I need to know if anyone has an easy way to merge two DataTables where the result of the merge is a DataTable with only rows that exist in both tables.

Dustin Ruckman
  • 103
  • 2
  • 14

1 Answers1

4

Like this:

var intersection = table1.AsEnumerable()
                         .Intersect(table2.AsEnumerable(), DataRowComparer.Default);

DataRowComparer compares rows by their column values.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964