Answer the question
In order to leave comments, you need to log in
How to combine subqueries?
All the best!
There are two subqueries select a set according to certain criteria, such as
select
id, dt_beg, dt_end
from ...................
where ..............
SELECT
ao.id,
DECODE(NVL(an.id,0), 0,ao.dt_beg, an.dt_beg) AS dt_beg,
DECODE(NVL(an.id,0), 0,ao.dt_end, an.dt_end) AS dt_end
FROM
(.....) ao, (.....) an
WHERE ao.id = an.id(+)
AND ao.id = _NUMBER_
;
SELECT
ao.id,
DECODE(NVL(an.id,0), 0,ao.dt_beg, an.dt_beg) AS dt_beg,
DECODE(NVL(an.id,0), 0,ao.dt_end, an.dt_end) AS dt_end
FROM
(.....) ao
FULL OUTER JOIN (.....) an ON ao.id = an.id
WHERE ao.id = _NUMBER_ OR an.id = _NUMBER_
;
Answer the question
In order to leave comments, you need to log in
PS: I'm sorry, I was in a hurry, I missed it ... according to the parameters that I chose, both requests were empty.
Everything is working:
SELECT
DECODE(NVL(an.id,0), 0,ao.id, an.id) AS id,
DECODE(NVL(an.id,0), 0,ao.dt_beg, an.dt_beg) AS dt_beg,
DECODE(NVL(an.id,0), 0,ao.dt_end, an.dt_end) AS dt_end
FROM
(.....) ao
FULL OUTER JOIN (.....) an ON ao.id = an.id
WHERE (an.id is null OR ao.id is null)
AND (ao.id = _NUMBER_ OR an.id = _NUMBER_)
;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question