0

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')
;



1
  • Sorry for the wrong query, updated the sub query. is it make sense now ? Commented Apr 26, 2020 at 18:20

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.