简体   繁体   中英

How can I add Table2 columns to table1

I have 2 sql query.

first select:

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

second select:

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

I want to first result set dt1 then second result set dt2. Finally I want add columns dt2 to dt1. from C#

You can use joins here to join the data of two or more tables:

Please refer the example given in the below link: enter link description here

Hope you find it useful.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM