ORACLE query using NOT IN too many values -
i have oracle
query below:
select * wa_ga_tbl_activity a, wa_ga_tbl_users u a.userid_fk = u.userid , (a.groupid_fk = 'gr0001' or u.groupid_fk = 'gr0001') , a.userid_fk != 'us0007' , (a.activityid) not in(select activityid_fk wa_ga_tbl_accessactivity userid_fk = 'us0007'
the first logic check in wa_ga_tbl_activity
when userid != us0007
. , want user details in not in
:
not in(select activityid_fk wa_ga_tbl_accessactivity userid_fk = 'us0007'
when userid_fk = us0007
i tried this:
select * wa_ga_tbl_activity a, wa_ga_tbl_users u a.userid_fk = u.userid , (a.groupid_fk = 'gr0001' or u.groupid_fk = 'gr0001') , a.userid_fk != 'us0007' , (a.activityid) not in(select s.userid, s.dateadded, w.activityid_fk wa_ga_tbl_users s, wa_ga_tbl_accessactivity w s.userid = w.userid_fk , w.userid_fk = 'us0007')
got error:
ora-00913: many values
sample data
table wa_ga_tbl_activity
activityid | activityname | userid_fk | activitydate | groupid_fk 001 | add new user | us0001 | 4/6/2017 | gr0001
table wa_ga_tbl_users
userid | username | dateadded us0001 | testuser1| 4/6/2017 us0007 | testuser2| 4/6/2017
table wa_ga_tbl_accessactivity
activityid_fk | userid_fk
is there way that?
the number of columns in projection of in
sub-query must match number referenced predicate. ora-00913: many values
error because (a.activityid)
not match (select s.userid, s.dateadded, w.activityid_fk
.
all need correlate
select * wa_ga_tbl_activity a, wa_ga_tbl_users u a.userid_fk = u.userid , (a.groupid_fk = 'gr0001' or u.groupid_fk = 'gr0001') , a.userid_fk != 'us0007' , (a.activityid) not in (select w.activityid_fk wa_ga_tbl_users s, wa_ga_tbl_accessactivity w s.userid = w.userid_fk , w.userid_fk = 'us0007')
it seems simplify subquery this
(select w.activityid_fk wa_ga_tbl_accessactivity w w.userid_fk = 'us0007')
but know business logic better do.
Comments
Post a Comment