Oracle SQL - Not Exists - string does not exist in a list of values -


background: spriden_id, sprhold_hldd_code may have 1 or more of several values or no values.

i need select sp.spriden_id, sp.spriden_last_name, sp.spriden_first_name, sr.shrdgmr_seq_no, sr.shrdgmr_program

where (sh.sprhold_hldd_code = 'rh') not exist.

so far, no records returned.

i have found if put code not in list of possible values (such z) in sh.sprhold_hldd_code = 'z', return results.

data: (column names abbreviated) spriden_id   spriden_last   spriden_first  shrdgmr_seq_no   shrdgmr_program sh.sprhold_hldd_code 100001       smith          sue            1                alhe            rh 100001       smith          sue            1                alhe            aa 100001       smith          sue            1                alhe            bb 100005       conners        tim            1                busn            rh 100008       occent         mary           1                math            cc 100008       occent         mary           1                math            aa  expected results: mary record not have rh code.  spriden_id   spriden_last_name   spriden_first_name  shrdgmr_seq_no  shrdgmr_program 100008       occent              mary                1                math               

i receive no results though.

code: select sp.spriden_id, sp.spriden_last_name, sp.spriden_first_name, sr.shrdgmr_seq_no,          sr.shrdgmr_program spriden sp join shrdgmr sr on sp.spriden_pidm = sr.shrdgmr_pidm join sprhold sh on sp.spriden_pidm = sh.sprhold_pidm sr.shrdgmr_degs_code = 'pn'   , sr.shrdgmr_term_code_grad >= '201489'   , sp.spriden_change_ind null , not exists (select sh.sprhold_pidm sprhold sh sh.sprhold_hldd_code = 'rh') 

to data want, recommend using aggregation having clause:

select sp.spriden_id, sp.spriden_last_name, sp.spriden_first_name, sr.shrdgmr_seq_no,         sr.shrdgmr_program spriden sp join      shrdgmr sr      on sp.spriden_pidm = sr.shrdgmr_pidm join      sprhold sh      on sp.spriden_pidm = sh.sprhold_pidm sr.shrdgmr_degs_code = 'pn' ,       sr.shrdgmr_term_code_grad >= '201489' ,      sp.spriden_change_ind null group sp.spriden_id, sp.spriden_last_name, sp.spriden_first_name, sr.shrdgmr_seq_no,           sr.shrdgmr_program having sum(case when sh.sprhold_hldd_code = 'rh' 1 else 0 end) = 0; 

you have 2 problems approach. first subquery either returns true or false , affects rows in original query. want correlated subquery. but, if got right, returning duplicate rows mary. solves both problems.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -