I am trying to select all submissions which don't exist in Quote or Policy table.
select
COUNT (*)
from Submission S
where
(S.Submission_Status='New' OR S.Submission_Status='Quoted to Agent' OR S.Submission_Status='Cleared')
and YEAR(S.Submission_Date) >= YEAR( GETDATE())
and S.Submission not in (select distinct Submission from Policy where Submission is not null)
and S.Submission not in (select distinct Submission from Quote where Submission is not null)
This query returns good results but query is extremely slow (since there are lot of records in Policy and Quote tables). Is it possible to make faster version of this query (I guess with JOIN)?
Thanks,
Ilija
EDIT:
I have tried this but results don't match first query: