简体   繁体   中英

Using Oracle how do I conditionally select a column from two different tables based on two difference if statements?

I need to conditionally select a column from two different if statements and two different tables. In short, it looks like this in pseudo-code:

IF  
    TABLE_A.COLUMN_A = ‘ABC’ THEN TABLE_A.COLUMN_B 
ELSE IF 
    TABLE_B.COLUMN_F <>  0 THEN TABLE_C.COLUMN_C
END IF

How might someone do this in Oracle sql?

TIA

CASE might help, if these tables are somehow related (ie you can JOIN them (would a CROSS JOIN be an option?):

select case when a.column_a = 'ABC' then a.column_b 
            when b.column_f <> 0    then c.column_c
       end
from table_a a join table_b b on ...
               join table_c c on ...
where ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM