I tested this and this subquery is going to take a very long time to run, can you restructure this as a regular left join with parameters.