jayjaybigs
IS-IT--Management
Hello,
I have two tables: previous and current.
The two tables have similar data structures.
previous contain 45 records for cp.person_code = 200199.
current contain 46 records for cp.person_code = 200199.
I used full outer join on the two tables expecting at most 46.
Here is my code:
select cp.PERSON_CODE,
cp.FIRST_NAME,
cp.LAST_NAME,
cp.BATCH_CODE,
cp.PC_CODE,
cp.DESCRIPTION,
pp.PREVIOUS_AMOUNT,
cp.CURRENT_AMOUNT,
(pp.PREVIOUS_AMOUNT - cp.CURRENT_AMOUNT ) Difference
from current_pay cp full outer join previous_pay pp
on cp.PC_CODE = pp.PC_CODE
and cp.PERSON_CODE = pp.PERSON_CODE
and cp.CURRENT_COMP_PCCODE = pp.PREVIOUS_COMP_PCCODE
and cp.person_code = 200199
order by 1, 5
However, I am getting 31517 records with some records having NULL values in all all the fields expect for PREVIOUS_AMOUNT(actually lots of records like that).
Also, there are some PC_CODE that exist in previous_pay table and not in current_pay. I was expecting them to show up with this final query by using FULL OUTER JOIN. But they are not.
Please help
I have two tables: previous and current.
The two tables have similar data structures.
previous contain 45 records for cp.person_code = 200199.
current contain 46 records for cp.person_code = 200199.
I used full outer join on the two tables expecting at most 46.
Here is my code:
select cp.PERSON_CODE,
cp.FIRST_NAME,
cp.LAST_NAME,
cp.BATCH_CODE,
cp.PC_CODE,
cp.DESCRIPTION,
pp.PREVIOUS_AMOUNT,
cp.CURRENT_AMOUNT,
(pp.PREVIOUS_AMOUNT - cp.CURRENT_AMOUNT ) Difference
from current_pay cp full outer join previous_pay pp
on cp.PC_CODE = pp.PC_CODE
and cp.PERSON_CODE = pp.PERSON_CODE
and cp.CURRENT_COMP_PCCODE = pp.PREVIOUS_COMP_PCCODE
and cp.person_code = 200199
order by 1, 5
However, I am getting 31517 records with some records having NULL values in all all the fields expect for PREVIOUS_AMOUNT(actually lots of records like that).
Also, there are some PC_CODE that exist in previous_pay table and not in current_pay. I was expecting them to show up with this final query by using FULL OUTER JOIN. But they are not.
Please help