简体   繁体   中英

how to compare multiple columns with same value in Oracle SQL with OR

I have the below query where i am comparing multiple columns with same sub query multiple times. is there a way to call only one sub query compare with multiple columns. I know it is possible for AND but is it possible for OR .

select * from catalog 
where 
APPROVER_USER=(select usr_key from usr where usr_login='abcd')
or CERTIFIER_USER =(select usr_key from usr where usr_login='abcd')
or FULFILLMENT_USER =(select usr_key from usr where usr_login='abcd')
;



You seem to be comparing user_key in the subquery based on a specific user. There seems to be no need for the usr table at all:

select c.*
from catalog c
where 437391 in (c.APPROVER_USER, c.CERTIFIER_USER, c.FULFILLMENT_USER);

EDIT:

For the revised question, I would just recommend join :

select c.*
from catalog c join
     users u
     on u.usr_login = ? and
        u.user_key in (c.APPROVER_USER, c.CERTIFIER_USER, c.FULFILLMENT_USER);

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