SELECT v.valuation_id FROM valuation v LEFT JOIN valuation_task vt on vt.valuation_id = v.valuation_id AND vt.valuation_task_id = ( SELECT valuation_task_id FROM valuation_task y WHERE y.valuation_id = v.valuation_id AND y.valuation_task_name = 'Listing live' AND y.valuation_task_status = '3' )
For each valuation (valuation_id), I want to search the valuation_task table, for a task with the attributes taskname = 'Listing live' and task status = '3' (which means the task is completed). There are approximately 8 valuation tasks against each valuation. The query takes over a minute to execute which is obviously unworkable.
Screenshot of the valuation_task table attached. There are 15069 rows in the valuation_task table and circa 2000 rows in the valuation table.
Happy to provide any further information required.