Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute only one exists in SQL

I'm creating a report with iReport over an Oracle DB. I have to select some values depending on a condition like this:

AND EXISTS (SELECT 1 FROM TABLE_1 WHERE x = y)  
OR EXISTS (SELECT 1 FROM TABLE_2 WHERE z = y) 

is it possible to execute the second EXISTS only if the first is false?

like image 363
noizer Avatar asked Jan 19 '26 11:01

noizer


1 Answers

Try to use your conditions in brackets:

AND (
        EXISTS (SELECT 1 FROM TABLE_1 WHERE x = y)  
     OR EXISTS (SELECT 1 FROM TABLE_2 WHERE z = y)
    )
like image 113
Himanshu Jansari Avatar answered Jan 22 '26 04:01

Himanshu Jansari