全外连接还是联合? [英] FULL OUTER JOIN or UNION?

查看:16
本文介绍了全外连接还是联合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对如何使用 FULL OUTER 或 UNION 实现这一点感到困惑.我想以这样的方式加入结果

confused how to achieve this maybe with FULL OUTER or a UNION. I want to join results in such a way that

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 

推荐答案

你需要一个笛卡尔积连接或交叉连接..

You need a cartesian product join or Cross Join ..

SELECT 
  *
FROM
  table1, table2

SELECT
  * 
FROM 
  table1 CROSS JOIN table2

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

这篇关于全外连接还是联合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆