一尘不染

完全加入还是联合?

sql

可能是用FULL OUTER或UNION混淆了如何实现这一点。我想以这样的方式加入结果

Table1                     Table2
---------------           ----------------- 
ID  Name Salary           ID    Fruits
---------------           ----------------- 
1   John   1000           1     Apples 
1   Henry  4000           1     Mangoes 
1   Smith  1000           1     Tomatoes

结果应该是

ResultTable
       ------------------------
       ID Name  Salary  Fruits
       -----------------------   
       1  John  1000    Apples
       1  John  1000    Mangoes
       1  John  1000    Tomatoes
       1  Henry 4000    Apples
       1  Henry 4000    Mangoes
       1  Henry 4000    Tomatoes
       1  Smith 1000    Apples
       1  Smith 1000    Mangoes
       1  Smith 1000    Tomatoes

阅读 167

收藏
2021-05-30

共1个答案

一尘不染

您需要笛卡尔积连接或交叉连接..

SELECT 
  *
FROM
  table1, table2

或者

SELECT
  * 
FROM 
  table1 CROSS JOIN table2

(参考:http
:
//publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/sqlp/rbafymstcrojo.htm)

2021-05-30