How To Combine These 2 Queries into 1 Query ?
Code:
SELECT b.KPCNO
,b.KPC_FULL_NAME
,min(c.time) in_time
FROM xxkpc_hr_personnel_v2 b
,xxkpc_fingerscan_data_v c
WHERE to_char(c.userpin(+)) = b.KPCNO
AND b.type(+) = 'KPC Employee'
AND b.DESIGNATION is null
AND b.kpcno IS NOT NULL
AND to_char(c.trdate(+),'DD-MON-YYYY') = to_char(SYSDATE,'DD-MON-YYYY')
AND c.tr_type(+) = 'Admitted In'
AND c.unitno(+) not in ('Staff Exit Barrier','Staff Entry Barrier 1','Service Gate Entry Barrier','Staff Entry Barrier 2')
AND b.ORGANIZATION_ID=(select g.ORGANIZATION_ID from xxkpc_fn_web_personnel_v g where g.kpcno = :kpcno)
GROUP BY b.KPCNO
,b.kpc_full_name
UNION
SELECT b.KPCNO
,b.KPC_FULL_NAME
,min(c.time) in_time
FROM xxkpc_hr_pos_struct_code_comb a
,xxkpc_hr_personnel_v2 b
,xxkpc_fingerscan_data_v
WHERE b.position_id(+) = a.child_position_id
AND to_char(c.userpin(+)) = b.KPCNO
AND b.type(+) = 'KPC Employee'
AND b.kpcno IS NOT NULL
AND to_char(c.trdate(+),'DD-MON-YYYY') = to_char(SYSDATE,'DD-MON-YYYY')
AND c.tr_type(+) = 'Admitted In'
AND c.unitno(+) not in ('Staff Exit Barrier','Staff Entry Barrier 1','Service Gate Entry Barrier','Staff Entry Barrier 2')
AND a.PERANT_POSITION_ID = (select g.POSITION_ID from xxkpc_fn_web_personnel_v g where g.kpcno = :kpcno)
GROUP BY b.KPCNO
,b.kpc_full_name