[英]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 .
我知道AND是可能的,但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.您似乎正在根据特定用户比较子查询中的
user_key
。 There seems to be no need for the usr
table at all:似乎根本不需要
usr
表:
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
:对于修改后的问题,我只建议
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.