Forum Discussion
martipe1
Mar 05, 2025Copper Contributor
Two missing record from this query
I have the following query: SELECT '20'||SUBSTR(CAST(T1.LMDTM1 as VarCHar(15)), 2, 6) as Date, T1.LMFSTM as Status, T1.LMREF1 as CustPO, TRIM(T1.LMREF1) ||'-'||TRIM(T1.LMREF2) as Key, T1.LMREF2...
SivertSolem
Mar 07, 2025Iron Contributor
Despite the fact that you're technically in the wrong forum, this is a logic error.
Because of the "MAX" statement, you'll only get one match with that t1.LMDTM1 = (...) comparison.
Of course, returning more than one row on that subquery would lead to other errors.
I would attempt to replace your equality and subquery with a join, see if that helps.
SELECT
'20'||SUBSTR(CAST(T1.LMDTM1 as VarCHar(15)), 2, 6) as Date,
T1.LMFSTM as Status,
T1.LMREF1 as CustPO,
TRIM(T1.LMREF1) ||'-'||TRIM(T1.LMREF2) as Key,
T1.LMREF2 as Order,
T1.LMREF3 as GUID
FROM EXTSYSFCC.EXLLMQLD T1
JOIN EXTSYSFCC.EXLLMQLD T2
ON t2.LMREF2 = t1.LMREF2
WHERE
t1.LMTPC1 = 'ABC'
AND
t1.LMMSID = '123'
AND
t1.LMDTM1 = t2.LMDTM1;
In the future, Oracle PL SQL related questions should be asked at their community forum, in order to improve your chances for relevant replies.
SQL & PL/SQL - Oracle Forums