I need to run a sql query that takes 24s. I tried to create indices on the two datetime columns START_DATE and END_DATE but my connection gets interupted after 600s. Is there any way to write a faster query?
FROM ( SELECT * FROM table1
WHERE LOC_ID IN (%s)
AND START_DATE != END_DATE
AND START_DATE <= '2002-01-31'
AND END_DATE >= '2002-01-01') tbl1
table2 as tbl2
ON tbl1.ID = tbl2.ID
I tried moving the where clause outside which increased the duration to 120 seconds.
I changed the query to the suggestion but it still takes the 24s, i gained a few ms only