In the Oracle DB there are three tables, see below.
Table: *'People'*
Table: *'Dogs'*
Table: *'Cats'*
Here is a Fiddle with data to test : http://sqlfiddle.com/#!4/d7cb4
Depending on the result of a query from the *'People'* table, how can I proceed with a different query to request data further either from *'Dogs'* or *'Cats'*.
Simply saying I need to execute a corresponding query depending on the answer of the initial/main query. Here is what I tried, (which obviously does not work):
WITH CONDITION_CHECK AS (
SELECT ADORE
FROM PEOPLE
WHERE ADORE = 'dog' --here I will put my variable
)
SELECT
CASE
WHEN CC.ADORE = 'dog' THEN (SELECT * FROM DOGS)
WHEN CC.ADORE = 'cat' THEN (SELECT * FROM CATS)
ELSE NULL
END
FROM CONDITION_CHECK AS CC
What is the most common approach to set up a conditional statement in Oracle DB? And how can one execute it?
I have seen the [IF-THEN-ELSE Statement](https://www.techonthenet.com/oracle/loops/if_then.php) , but I do not understand it much.
----------
**References:**
- [Performing a query on a result from another query?](https://stackoverflow.com/questions/949465/performing-a-query-on-a-result-from-another-query)
- [Using IF ELSE statement based on Count to execute different Insert statements](https://stackoverflow.com/questions/14072140/using-if-else-statement-based-on-count-to-execute-different-insert-statements)
- [IF Condition Perform Query, Else Perform Other Query](https://stackoverflow.com/questions/17199604/if-condition-perform-query-else-perform-other-query)



Asked by Taras
(177 rep)
Jun 14, 2022, 12:12 PM
Last activity: Jun 15, 2022, 11:32 AM
Last activity: Jun 15, 2022, 11:32 AM