Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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_Oracle_Join - Fatal编程技术网

SQL:使用联接添加列

SQL:使用联接添加列,sql,oracle,join,Sql,Oracle,Join,在我的数据库中,我想将其中一个视图和所有列添加到另一个视图中 视图一: |Col1 | Col2 | | | | | | | | | | 观点二: |Col1 | Col3 | Col4| Col5 | | | | | | | | | | | | | | | | 我期望的结果是: |Col1 | Col2 | Col3 | Col4

在我的数据库中,我想将其中一个视图和所有列添加到另一个视图中

视图一:

|Col1 | Col2 |
|     |      |
|     |      |
|     |      |
观点二:

|Col1 | Col3 | Col4| Col5 |
|     |      |     |      |
|     |      |     |      |
|     |      |     |      |
我期望的结果是:

|Col1 | Col2 | Col3 | Col4 |
|     |      |      |      |
|     |      |      |      |
|     |      |      |      |
我尝试过以下解决方案:

SELECT Col1, Col2
FROM view1 NATURAL JOIN(
SELECT Col1, Col2, Col3, Col4
FROM view2); 
我也尝试过其他连接,但不断得到错误,我缺少关键字


如何按我希望的方式组合表?

我不知道视图的模式是什么,但我假设两个视图中的col1匹配

SELECT v1.Col1, v1.Col2, v2.Col3,v2.col4
FROM View1 v1
INNER JOIN -- OR FULL OUTER JOIN based on your desired result
View v2
on
v1.col1=v2.col1 -- AND/OR any other matching columns. I couldn't find any other one

view1中是否存在view2中不存在的col1?view2中是否有col1在view1中不存在?col1 view1中的所有值在col1 view2中都存在,但view2中可能有不在view1中的值。然后使用Codeek的建议和外部连接view1到view2(
从view1右连接view2
从view2左连接view1
)。