Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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
Oracle连接查询_Oracle_Join_Inner Join - Fatal编程技术网

Oracle连接查询

Oracle连接查询,oracle,join,inner-join,Oracle,Join,Inner Join,我有两张桌子 表A有列id | name | age 表B有列id | name | age 表A中的样本记录 1|xavi |23 2|christine|24 3|faisal |25 5|jude |27 表B中的样本记录 1|xavi |23 2|christine|22 3|faisal |23 4|ram |25 如果表A中的id值与表B中的匹配,则仅从表A中获取记录。 同时,只记录表A中的记录 还应记录表B中的记录 所以我的结果应该

我有两张桌子

  • 表A有列
    id | name | age
  • 表B有列
    id | name | age
表A中的样本记录

1|xavi     |23
2|christine|24
3|faisal   |25
5|jude     |27
表B中的样本记录

1|xavi     |23
2|christine|22
3|faisal   |23
4|ram      |25
如果表A中的id值与表B中的匹配,则仅从表A中获取记录。 同时,只记录表A中的记录 还应记录表B中的记录

所以我的结果应该是

1|xavi     |23
2|christine|24
3|faisal   |25
4|ram      |25
5|jude     |27
<>一些要考虑的事情-->除非你正在更新特定的表和记录是相同的,你从哪个表中查看记录是无关紧要的(因为它们是相同的……)。
如果您想查看记录是从哪个表派生的,请告诉我,我也将向您演示如何执行此操作。。。但是查询更复杂,我真的认为上面描述的目的不需要它。让我知道这是否有帮助。。。谢谢,Brian

您可以简单地使用union运算符从两个表中获取唯一的值。运算符联合将删除重复的值

SELECT * FROM tableA AS t1
UNION
SELECT * FROM tableB AS t2

如果表与您需要的关系密切:

Select DISTINCT * 
  from tableA a
 Inner Join tableB b
    On a.id = b.id
如果没有:

在使用UNION和DISTINCT之后,必须使用UNION。
DISTINCT将不允许重复行。

此处存在优先级问题。从表A中取出所有记录,然后从表B中取出额外记录:

select *
from A
union all
select *
from B
where B.id not in (select A.id from A);
您还可以使用
完全外部联接
来表示这一点(假设
id
在两个表中都不重复):

在这种情况下,
coalesce()
优先考虑
A
中的值

select *
from A
union all
select *
from B
where B.id not in (select A.id from A);
select coalesce(A.id, B.id) as id,
       coalesce(A.name, B.name) as name,
       coalesce(A.age, B.age) as age
from A full outer join
     B
     on A.id = B.id;