I have query as given below:
SELECT * FROM [PMDB_DEV].[dbo].[TRSRCFIN]
WHERE proj_id = 167592
AND taskrsrc_id NOT IN
(
SELECT taskrsrc_id FROM [PMDB_ARC].[dbo].[TRSRCFIN_TEST]
WHERE proj_id = 167592
)
UNION
SELECT * FROM [PMDB_DEV].[dbo].[TRSRCFIN]
WHERE proj_id = 167592
AND fin_dates_id NOT IN
(
SELECT fin_dates_id FROM [PMDB_ARC].[dbo].[TRSRCFIN_TEST]
WHERE proj_id = 167592
)
Basically the query returns all the rows where either taskrsrc_id or fin_dates_id should not present in the subquery data.
Can I do this without using UNION??
Thanks, Mahesh
select *
from [PMDB_DEV].[dbo].[TRSRCFIN] t1
where proj_id = 167592
and not exists
(
select *
from [PMDB_ARC].[dbo].[TRSRCFIN_TEST] t2
where t2.proj_id = t1.proj_id
and (
t1.taskrsrc_id = t2.taskrsrc_id
or
t1.fin_dates_id = t2.fin_dates_id
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With