Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将多个表合并到一个表中_Sql_Sql Server 2008 R2 - Fatal编程技术网

Sql 将多个表合并到一个表中

Sql 将多个表合并到一个表中,sql,sql-server-2008-r2,Sql,Sql Server 2008 R2,如果我的tlb1为: col1 1 2 3 现在我将tlb2作为: col2 col3 4 Four 5 Five 6 SIX 不,我有tlb3 col4 col5 sample14 sample15 sample24 sample25 sample34 sample35 如果我希望结果为: col1 col2 col3 col4 col5

如果我的tlb1为:

col1

1

2

3
现在我将tlb2作为:

col2   col3

 4     Four  

 5     Five  

 6     SIX
不,我有tlb3

   col4          col5

    sample14     sample15

    sample24     sample25

    sample34     sample35
如果我希望结果为:

col1 col2   col3   col4       col5     

1     4     Four   sample14   sample15 

2     5     Five   sample24   sample25

3     6     Six    sample34   sample35
我试过:

select ( (select * from tlb1), (select * from tlb2),(select * from tlb3)) T
但这失败了

请帮帮我

 with t1 as (select col1, row_number() over (order by col1) rn from tbl1 ),
 t2 as (select col2,col3, row_number() over (order by col2) rn from tbl2),
 t3 as (  select col4,col5, row_number() over (order by col4) rn  from tbl3) 
 select t1.col1,t2.col2,t2.col3,t3.col4,t3.col5 
 from t1 full outer join t2 on t1.rn = t2.rn
 t3 full outerjoin t2 on t2.rn = t3.rn

尝试这样的方法…

为什么要合并完全不相关的数据?如果表中的行数不同,该怎么办?不同的行数只会造成问题..是的,你看!还认为这是个好主意吗?请记住,数据中没有顺序,您希望联接的表之间的公共因子是什么?同样,您不能说“行顺序”,因为没有行顺序。数据中没有公共因素是的,这在某种程度上对我有用。。如果有什么困难,我会给你回电话