Home SQL left join takes too long
Reply: 0

SQL left join takes too long

user788 Published in May 22, 2018, 11:22 pm

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?

SELECT tbl1.*,
         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
         LEFT JOIN 
            table2 as tbl2
                ON tbl1.ID = tbl2.ID

EDIT: 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

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305872 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO