t-sql乘以两个表

时间:2012-10-16 13:03:17

标签: sql-server tsql

我有2张桌子

Plant            config         
------         --------

TRZ1            KS

MAS1            MT

我想在下面有两列

的表格
RESULT
------
TRZ1  KS

TRZ1  MT

MAS1  KS

MAS1   MT

感谢您的帮助

3 个答案:

答案 0 :(得分:1)

目前尚不清楚是否需要在同一列中,如果是这样,那么您可以使用以下方法连接值:

select p.col1 + ' ' + c.col1 as result
from plant p
outer apply config c

请参阅SQL Fiddle with Demo

如果没有,那么你可以使用:

select p.col1 plant, c.col1 config
from plant p
outer apply config c

请参阅SQL Fiddle with Demo

答案 1 :(得分:0)

最短路:

   select * from plant, config

答案 2 :(得分:0)

使用可以使用CROSS JOIN:

  

SELECT P.NAME,C.NAME FROM Plant AS P CROSS JOIN Config AS C