어떻게된 영문인지 도저히 모르겠습니다...
AND 조건이 추가되면 오히려 조회되는 row 가 늘어나는데 이럴수가 있나요..?
with recursive hsra_tmp as ( select t.*, t.hsra_id root_id, 1 lev, concat(t.hsra_req_title) as full_code_name from eso_hsra t where hsra_src_id is null union all select t.*, p.root_id, p.lev+1 lev, concat(p.full_code_name ,'/' , t.hsra_req_title) as full_code_name from eso_hsra t, hsra_tmp p where t.hsra_src_id = p.hsra_id ) select hsrp_id "key" , full_code_name AS hsrp_acc_proc ,hsrp_tas_id ,t.hsra_id ,x.hsrp_acc_proc from eso_hsrp x ,hsra_tmp t WHERE 1=1 and hsrp_acc_proc = t.hsra_id
원래 이렇게 있는 쿼리에서
AND x.hsrp_tas_id='TAS02306' OR x.hsrp_tas_id='TAS02321' OR x.hsrp_tas_id='TAS02343'
해당 조건문을 추가하면 hsrp_tas_id 의 조건 데이터만 추려져야하는데 조회건수가 확 늘어납니다..
무엇이 문제일까요?
WHERE 에서 AND와 OR가 혼용 되었을 경우 AND 먼저 실행하고 OR를 실행합니다.
그러므로 AND x.hsrp_tas_id='TAS02306' OR x.hsrp_tas_id='TAS02321' OR x.hsrp_tas_id='TAS02343'를 추가하면
hsrp_acc_proc = t.hsra_id AND x.hsrp_tas_id='TAS02306'를 기준으로 먼저 데이터를 가져오고 x.hsrp_tas_id='TAS02321' 이거나 x.hsrp_tas_id='TAS02343'인 데이터도 가져오겠네요.
괄호를 이용하시면 됩니다.
AND (x.hsrp_tas_id='TAS02306' OR x.hsrp_tas_id='TAS02321' OR x.hsrp_tas_id='TAS02343')