I have ORA-00918 error with my code and i could not find the problem... the following code gives me this error.
ORA-00918 : column ambiguously defined
can anyone give me some advice? thanks
SELECT * FROM (
SELECT * FROM (
SELECT ROWNUM AS RNUM, A.XML_MSG_ID, A.LOGIN_ID, A.ORIGINATOR, A.RECIPIENT, A.ERROR_CODE, B.DOC_NO, B.DOC_NAME, B.ERROR_MSG
FROM XML_MANAGE_TBL A, XML_REFERENCE_TBL B
WHERE A.XML_MGS_ID = B.XML_MSG_ID
AND A.ERROR_CODE <> '00000000'
AND A.XML_MSG_ID >= '20190528' AND (SUBSTR(A.XML_MSG_ID, 1, 8)) <= '20190604' ) C, EBILL_USER D WHERE D.COMP_NUM = '1258169573' AND C.ORIGINATOR = D.ORIGINATOR )
WHERE RNUM BETWEEN CASE WHEN (1-1) != 0 THEN ((1-1)*50)+1 ELSE (1-1)*50 END
AND 1*50;
The problem is most probably in second subquery
select *The table
Dcontains the same columns as the subqueryC, for sure theORIGINATORcolumnSimple change the second query to
SELECT C.*and add only the required columns fromD.The general aproach how to troubleshoot
ORA-00918is to run the query from the innermost subquery and check that the returned column names are unique.In your case try first, which should be fine
Than run the second innermost subquery
In your IDE (e.g. SQL Developer) you will see one and more columns with a suffix
_1which is a sign of duplicated column that must be excluded (for columns from the equijoin predicate) or renamed.