2008-12-06 123 views
0

的我试图合并的表其是fus_shift和根表到一个新的表,该表是最后的表但在第2行输出,如“ERROR: ORA-01789:查询块具有不正确的结果列数“。我也尝试加入表作为我的选择,但它也输出“错误在第3行:ORA-00918:列模糊定义”。是否有另一种方法来组合和连接两个不同列数的表,并分别具有相同的列名称?再次感谢:-)

代码错误:
创建表最终为
SELECT * FROM fus_shift
工会
SELECT * FROM根;
结合并连接两个不同的号码表。列和相同的列名

代码错误:
选择record_num,test_num,t_date,t_time,system_type,类别,评论,VAL
从fus_shiftrpt,根
其中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 

强调文本

回答

3

你当然不能 “联盟” 适用于你的表。只有当两个查询返回相同的数字(以及类似的类型)的列时,才能应用它。

您可以加入这两个表,但在加入时必须使用“表别名”,因为“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; 
+0

有没有必要使用表别名来解决查询; WHERE子句完全可以是'WHERE fus_shift.record_num = root.record_num'。 – 2008-12-06 10:49:46

+0

这也可以工作。如果我们不想使用表别名,除了WHERE子句,我们还必须使用表名解析SELECT子句中的公共字段。 – MOZILLA 2008-12-06 14:54:09

1

我会用下面的方法:

SELECT * 
FROM fus_shift 
INNER JOIN root ON root.record_num = fus_shift.record_num 
相关问题