I have below two tables which i need to combine together into my daily reports.
Table 1: Resource_Created
FirstName LastName ObjDate Resource Login
TestDemo1 TestDemo1 5-Oct-12 AD TESTDEMO1
Table 2: Resource_Deleted
FirstName LastName ObjDate Resource Login
TestDemo4 TestDemo4 5-Oct-12 AD TESTDEMO4
TestDemo5 TestDemo5 5-Oct-12 AD TESTDEMO5
TestDemo6 TestDemo6 5-Oct-12 AD TESTDEMO6
TestDemo4 TestDemo4 5-Oct-12 Bio TESTDEMO4
TestDemo4 TestDemo4 5-Oct-12 VPN TESTDEMO4
TestDemo5 TestDemo5 5-Oct-12 VPN TESTDEMO5
TestDemo6 TestDemo6 5-Oct-12 VPN TESTDEMO6
I wrote two queries individually like
Query 1:
select distinct Resource as Resource,
count (distinct Login) as CountRes
from Resource_Created
where ObjDate between '4-Oct-12' and '6-Oct-12'
group by Resource ;
Result:
Resource CountRes
AD 1
Query 2:
select distinct Resource as Resource,
count (distinct Login) as CountRes
from Resource_Deleted
where ObjDate between '4-Oct-12' and '6-Oct-12'
group by Resource ;
Result
Resource CountRes
AD 3
VPN 3
Bio 1
I wish to combine these two queries, so that i can have one table display these values.
select COALESCE (Resource_Created.Resource, Resource_Deleted.Resource) as Resource ,
count (distinct Resource_Created.usrlogin) as aobj,
count (distinct Resource_Deleted.usrlogin) as bobj
FROM target_failed FULL OUTER JOIN target_resource
on Resource_Created.Resource = Resource_Deleted.Resource
where
Resource_Created.ObjDate between '04-OCT-2012' and '06-OCT-2012' and
Resource_Deleted.ObjDate between '04-OCT-2012' and '06-OCT-2012'
group by COALESCE(Resource_Created.Resource, Resource_Deleted.Resource);
My Result was
**Resource aobj bobj**
AD 1 3
Expected Result
Resource aobj bobj
AD 1 3
VPN Null 3
Bio Null 1
Please could anyone help me resolve the issue. I am just a OO developer who writes basic sql queries. It would be greatly appreciated.
Simply use sub sql on from statement