合并两个表数据

时间:2016-01-28 16:03:01

标签: join oracle11g union-all

enter image description here

我有两个表A和B,我需要通过组合这两个表来生成报告,输出应该如下图所示。我怎样才能实现它。请帮帮我。

1 个答案:

答案 0 :(得分:1)

我认为以下内容可以与联盟一起使用。它将对两个表进行全表扫描,如果这些表有大量数据,这可能是一个值得关注的问题。请先检查查询计划。

select A_INFRASTRUCTURE_CHANGE_ID, A_Name_c, A_Support_group, B_INFRASTRUCTURE_CHANGE_ID, B_Steps_c, B_Support_group
FROM
    (SELECT  INFRASTRUCTURE_CHANGE_ID as A_INFRASTRUCTURE_CHANGE_ID, Name_c as A_Name_c, 
         Support_group as A_Support_group, NULL as B_INFRASTRUCTURE_CHANGE_ID , NULL as B_Steps_c, NULL  as B_Support_group 
FROM TABLE_A
UNION ALL 
 SELECT NULL as A_INFRASTRUCTURE_CHANGE_ID,NULL as A_Name_c,NULL as A_Support_group ,
        INFRASTRUCTURE_CHANGE_ID as B_INFRASTRUCTURE_CHANGE_ID, Steps_c as B_Steps_c, Support_group as B_Support_group 
FROM TABLE_B); 

Sabiha