Oracle在不同的表上查询具有相同id列名的数据

时间:2018-01-15 03:27:44

标签: sql oracle

我尝试使用以下代码运行Oracle数据查询:

SELECT
    S.FORM_NO,
    S.ARTICLEID_FK AS S_ARTICLEID_FK,
    S.BOX_SERIAL_NO,
    S.ACTUAL_WEIGHT,
    TO_CHAR(S.DATEADDED, 'DD-MON-YYYY HH24:MI:SS') AS DATEADDEDS,
    S.ADDEDBY,
    B.ARTICLEID_FK AS B_ARTICLEID_FK,
    B.DATE_CODE
FROM
    WA_LA_TBL_ARTICLES_SCAN S,
    WA_LA_TBL_ARTICLES_BOX_SN B
WHERE
    S.S_ARTICLEID_FK = B.B_ARTICLEID_FK

现在得到以下错误:

Warning: oci_execute(): ORA-00904: "S"."S_ARTICLEID_FK": invalid identifier in...

我怀疑可能来自这方:S.ARTICLEID_FKB.ARTICLEID_FK

但我不知道如何解决查询。

3 个答案:

答案 0 :(得分:2)

SELECT
    S.FORM_NO,
    S.ARTICLEID_FK AS S_ARTICLEID_FK,
    S.BOX_SERIAL_NO,
    S.ACTUAL_WEIGHT,
    TO_CHAR(S.DATEADDED, 'DD-MON-YYYY HH24:MI:SS') AS DATEADDEDS,
    S.ADDEDBY,
    B.ARTICLEID_FK AS B_ARTICLEID_FK,
    B.DATE_CODE
FROM
    WA_LA_TBL_ARTICLES_SCAN S,
    WA_LA_TBL_ARTICLES_BOX_SN B
WHERE
    S.ARTICLEID_FK = B.ARTICLEID_FK 

答案 1 :(得分:1)

尝试:

WHERE S.ARTICLEID_FK = B.ARTICLEID_FK

您似乎正在尝试使用新字段S.S_ARTICLEID_FK = B.B_ARTICLEID_FK作为连接的ID,这就是问题......

答案 2 :(得分:0)

学习使用正确的JOIN语法。然后,您无法在ONWHERE中使用列别名:

SELECT . . .
FROM WA_LA_TBL_ARTICLES_SCAN S JOIN
     WA_LA_TBL_ARTICLES_BOX_SN B
     ON S.ARTICLEID_FK = B.ARTICLEID_FK;