sql - How To Combine These 2 Queries into one Query without using union -
select b.kpcno ,b.kpc_full_name xxkpc_hr_personnel_v2 b b.type(+) = 'kpc employee' , b.designation null , b.kpcno not null , b.organization_id=(select g.organization_id xxkpc_fn_web_personnel_v g g.kpcno = :kpcno) group b.kpcno ,b.kpc_full_name union select b.kpcno ,b.kpc_full_name xxkpc_hr_pos_struct_code_comb ,xxkpc_hr_personnel_v2 b b.position_id(+) = a.child_position_id , b.type(+) = 'kpc employee' , b.kpcno not null , a.perant_position_id = (select g.position_id xxkpc_fn_web_personnel_v g g.kpcno = :kpcno) group b.kpcno ,b.kpc_full_name please need combine these 2 queries 1 query without using union
i think can write like:
select distinct b.kpcno, b.kpc_full_name xxxkpc_hr_personnel_v2 b b.type(+) = 'kpc employee' , b.kpcno not null , ( (b.designation null , b.organization_id in (select g.organization_id xxkpc_fn_web_personnel_v g g.kpcno = :kpcno)) or (b.position_id in (select a.child_position_id xxkpc_hr_pos_struct_code_comb a.parent_position_id = (select g.position_id xxkpc_fn_web_personnel_v g g.kpcno = :kpcno))) ) as far see using group by make result distinct, used proper key word. , a , b not left joined, because in next anded clause saying a.parent_position_id = .....
Comments
Post a Comment