sql - oracle self outer join filtering records -


select a.emp_id a_emp_id,   a.emp_code a_emp_code,   b.emp_id b_emp_id,   b.emp_code b_emp_code,   c.emp_id c_emp_id,   c.emp_code c_emp_code, emp left outer join emp b on a.u_code =b.u_code left outer join emp c on a.u_code =c.u_code a.src ='a' , b.src  ='b' , c.src  ='c' 

for 1 employee have data different sources , id different systems. there more 5 different source system data coming table. u_code remain same in sources. emp having each row each system.

now, need build cross walk table in 1 row can give source system id single employee. above query working fine if employee having data in 3 systems filtering out data if present in 2 systems.

table data

empid,emp_code,src,u_code 1,abc,a,101 2,pqr,b,101 3,xyz,c,101 4,kpo,a,102 5,lip,b,102 

query should return

a_emp_id,a_emp_code,b_emp_id,b_emp_code,c_emp_id,c_emp_code 1,abc,2,pqr,3,xyz,101 4,kpo,5,lip,,,102 

query working fine 101 u_code not returing 102

database oracle 10g

when have outer join, need careful conditions in where clause. think intend:

select . . . emp left outer join      emp b      on a.u_code = b.u_code , b.src = 'b' left outer join      emp c     on a.u_code = c.u_code , c.src  = 'c' a.src = 'a' 

what happening in version non-matching rows in b , c generated filled null values. null values fail where conditions, these rows filtered out. effect same doing inner join.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -