如何将Table2列添加到table1

时间:2019-03-02 15:05:40

标签: c# sql

我有2条sql查询。

首先选择:

string sql1 ="@select ( ...... )"
DbCommand command1 = db.GetSqlStringCommand(sql1);
DataTable dt1 = base.Select(command1);    

第二次选择:

 string sql2 ="@select ( ...... )"
 DbCommand command = db.GetSqlStringCommand(sql2);
 DataTable dt2 = base.Select(command);

我想要第一个结果集dt1,然后第二个结果集dt2。最后,我想将dt2列添加到dt1中。来自C#

2 个答案:

答案 0 :(得分:0)

假设两个查询中的列相同,最简单的方法是使用union all

string sql = "@select ( ...... ) union all @select ( ...... )"

答案 1 :(得分:0)

您可以在此处使用联接来联接两个或多个表的数据:

请参考以下链接中给出的示例: enter link description here

希望您发现它有用。