将列添加到 table 并在之后自动 UNION tables

Adding column to table and automatically UNION tables afterwards

我有以下问题:

我有一个 table 具有不同的 ID 和 Indicator 对。

    Table A:
    ID         Indicator        
    ----------------------
    1            1       
    1            2         
    1            3          
    2            1     
    2            2             
    2            3     
    ----------------------

第二个 table 具有不同的名称。

    Table B:
    Names                 
    -------
    John                                   
    Lea                      
    Peter                                      
    --------

我想要的是 table A 中的一列,每个 ID-Indicator 对的名称为 Table B:

    Outcome:
    ID         Indicator    Names    
    ----------------------------------
    1            1          John
    1            2          John         
    1            3          John          
    2            1          John     
    2            2          John             
    2            3          John     
    1            1          Lea
    1            2          Lea         
    1            3          Lea          
    2            1          Lea     
    2            2          Lea             
    2            3          Lea  
    1            1          Peter
    1            2          Peter         
    1            3          Peter          
    2            1          Peter     
    2            2          Peter             
    2            3          Peter  
    ----------------------------------

实际上 Table B 的名字真的很长,所以手动解决方案如:

SELECT ID, Indicator, Names = 'John'
FROM TableA
UNION
SELECT ID, Indicator, Names = 'Lea'
FROM TableA

不可行。这个问题有非手动解决方案吗? 非常感谢任何帮助!

您想要将 TableA 中的每一行与 TableB 中的每一行连接起来,这称为 cross 连接,如评论所述。输出的行数将为 A * B.

如果您想要两个表中的所有列,语法很简单

select * 
from TableA cross join TableB