---
title: "Full outer join, on 2 data tables, with a list of columns"  
description: "Full outer join, on 2 data tables, with a list of columns"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1216/full-outer-join-on-2-data-tables-with-a-list-of-columns  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Full outer join, on 2 data tables, with a list of columns

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
I have 2 data tables, which I do not know their list of data columns. This list must be extracted at run time, and be used for the full [outer join](https://www.mindstick.com/forum/159328/mysql-outer-join-syntax-error).\
When using these columns, the columns between the 2 tables need to be merged, and I need all data to be displayed.\
[Till now](https://answers.mindstick.com/qa/40087/which-is-the-best-indian-tv-serial-till-now) what I am doing is \
Get [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) columns, using [intersect](https://www.mindstick.com/forum/34040/use-intersect-in-sql-server), and implementing IEqualityComparerCreate a new [datatable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net), with these columns, so that the 2 datatables will be merged into this new tableHowever, I am having [issues](https://www.mindstick.com/articles/12944/mattresses-for-kids-and-mothers-should-meet-certain-criteria-issues-you-should-consider) with Linq, on the 2nd step.\
Till now I have :\
Get common columns\
// Get common columns var commonColumns = dt1.Columns.OfType().Intersect(dt2.Columns.OfType(), new DataColumnComparer());\
Create new data table\
// Create the [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) which is going to be sent to the user DataTable result = new DataTable();\
// Add all the columns from both tables result.Columns.AddRange( dt1.Columns.OfType() .Union(dt2.Columns.OfType(), new DataColumnComparer()) .Select(c => new DataColumn(c.Caption, c.DataType, c.Expression, c.ColumnMapping)).ToArray());\
How can I obtain an [efficient](https://www.mindstick.com/articles/33637/three-tips-for-an-energy-efficient-home-for-2019) [full outer](https://www.mindstick.com/forum/33754/how-to-use-sql-full-outer-join) join dynamically, from the List of datacolumns, that is extracted at run time?

## Replies

### Reply by Sumit Kesarwani

Hi Chintoo,\
try this,\
**var commonColumns = dt1.Columns.OfType<DataColumn>().Intersect(dt2.Columns.OfType<DataColumn>(), new DataColumnComparer());** **DataTable result = new DataTable();****\** **dt1.PrimaryKey = commonColumns.ToArray();****\** **result.Merge(dt1, false, MissingSchemaAction.AddWithKey);** **result.Merge(dt2, false, MissingSchemaAction.AddWithKey);**\
I hope it work fine.


---

Original Source: https://www.mindstick.com/forum/1216/full-outer-join-on-2-data-tables-with-a-list-of-columns

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
