I have the following query that having a sub-query to select from dual. Both result of main and subquery need to be display in the output.
SELECT
a.ROW_EXISTS AS CLIENT_EXIST,
c.AP_Before AS AP_before,
c.AP_TIMESTAMP AS AP_TIMESTAMP,
cd.AAM_FLAG AS AAM_FLAG,
cd.SSM_FLAG AS SSM_FLAG
FROM
(
select
case when exist (select 1 from c.clients where client_id='c-001' then 'Y' else 'N' end as ROW_EXISTS
from dual
) AS a
INNER JOIN CLIENT_DYN cd ON c.CLIENT_ID = cd.CLIENT_ID
WHERE c.CLIENT_ID = 'c-001';
Error ORA-00933: SQL command not properly ended
encounters near line ) AS A
when execute the query.
After you fix the syntax errors (
EXISTS
notEXIST
, missing closing brace and don't use theAS
keyword for table aliases), your outer query isThere is no
c
table or alias in the outer-query as the sub-query is aliased toa
notc
and the sub-query only contains onerow_exists
column and not aCLIENT_ID
column; so on both these points,c.CLIENT_ID
is invalid.What you probably want is something like:
If you want to check the
client_id
matches the current row:or, if you want to check if the
client_id
matches in the set of returned rows:or, if you want to check if the
client_id
exists anywhere in theclients
table:Depending on how you want to check if the client exists.