结合并连接两个不同的表。列和相同的列名称

时间:2008-12-06 09:35:09

标签: sql oracle sqlplus ora-00918

我尝试将 fus_shift和root表的表组合到一个新表中,该表是最终表,但输出类似于第2行的错误: ORA-01789:查询块的结果列数不正确“。我尝试将表格作为替代方案加入,但它也输出”第3行的错误:ORA-00918:列模糊定义 “。是否有另一种方法可以分别组合和连接两个具有不同列数并具有相同列名的表?再次感谢:-)

代码错误:
创建表final作为
从fus_shift中选择* 工会
从根目录中选择*;

代码错误:
选择record_num,test_num,t_date,t_time,system_type,category,comments,val
来自fus_shiftrpt,root
其中record_num = record_num;

我的桌子:

                                 fus_shift Table


           Record_Num       test          date      time         system   
           -----------------------------------------------------------
                1          test15      08-11-12  13:20:01    sys23 
                2          test17      08-11-03  14:24:00    sys24
                3          test13      08-11-13  17:25:04    sys45
                4          test15      08-11-14  18:24:00    sys67
                5          test16      08-11-15  19:24:06    sys45


                                 root Table

           Record_Num      category   comments    validated by
           ---------------------------------------------------
                  1        dirt        checked        admin
                  2        prog        checked        admin
                  3        dirt        checked        pe
                  4        wires       checked        ee
                  5        prog        repair         admin

强调文字

2 个答案:

答案 0 :(得分:3)

你当然不能在你的牌桌上申请“联盟”。只有当两个查询返回相同数量(和类似类型)的列时,才能应用它。

您可以加入这两个表,但在加入时必须使用“table alias”,因为“record_num”字段在两个表中都很常见。这是适合您的查询

select 
        table1.record_num,
        table1.test_num,
        table1.t_date,
        table1.t_time,
        table1.system_type,
        table2.category,
        table2.comments,
        table2.val
from 
       fus_shift table1,root table2
where 
       table1.record_num = table2.record_num;

答案 1 :(得分:1)

我会使用以下方法:

SELECT * 
FROM fus_shift
INNER JOIN root ON root.record_num = fus_shift.record_num