title: SQL left join takes too long
body: <p>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?</p>
  
  <pre><code>SELECT tbl1.*,
           tbl2.NAME
           FROM (  SELECT * FROM table1
                  WHERE LOC_ID IN (%s)
                  AND START_DATE != END_DATE
                  AND START_DATE &lt;= '2002-01-31' 
                  AND END_DATE &gt;= '2002-01-01') tbl1
           LEFT JOIN 
              table2 as tbl2
                  ON tbl1.ID = tbl2.ID
  </code></pre>
  
  <p>EDIT:
  I tried moving the where clause outside which increased the duration to 120 seconds.</p>
  
  <p>I changed the query to the suggestion but it still takes the 24s, i gained a few ms only</p>