I have an sql query:
select person from table t1
inner join person_history ph
on t1.person = ph.person
and t1.person not in (select person from person_history
where effective_date < '01-01-2013')
and ph.person.effective_date > '01-01-2013'
since person_history
contains a lot of records, this query is taking too long.
How can I optimize this code?