I have a nested MySQL query having relation in tables with over 500000 records in each. The query takes 60 seconds to fetch results and Indexing has been done in all tables.
Please suggest to reduce its execution time. Thanks in advance.
SELECT t1.col1,t1.col2
FROM table1 AS t1
WHERE t1.col2 IN
(
SELECT DISTINCT(t2.col1) FROM table2 AS t2 WHERE t2.col2 IN
(
SELECT t3.col1
FROM table3 AS t3
WHERE t3.col2 = '04' ORDER BY t3.col1 ASC
)
ORDER BY t2.col1 ASC
)
DISTINCTclause you have as they can often cause delay. In addition you could try using aJOINinstead ofWHERE ... INas that can often be faster.where...in