I'm trying to make a SQL request but that request is taking forever to finish. The request is done in Excel 2003 with VBA.
Size of the TABLE:
- TABLE1 = 12600 Row
- TABLE2 = 361K Row
Here's the query:
SELECT DISTINCT y.code AS CODE, y.name AS LIBELLE, #[...] #[...] #[...] #[...] y.IS_BILAN, y.INACTIVE, (SELECT COUNT(1) FROM TABLE1 d, TABLE2 a WHERE a.record_date_time >= '2018/01/01' AND a.record_date_time < '2019/01/01' AND global_status <> 'C' AND a.id = d.id AND d.type_id = y.code) AS TOTAL_2018 FROM anal_exam y ORDER BY code
The whole query run instantly when removing the last part "SELECT COUNT(1)"
The execution plan I see in Oracle SQL Developer:
How could I speed up this query? It takes 47 minutes to finish