Skip to content
Advertisement

Optimizing subquery in sql [closed]

Given the following SQL query

Recently this query has been taking longer to execute and as I am new to SQL I am wondering if there is anyway to optimize it further? I feel I may not have the most optimal query.

Advertisement

Answer

In general subqueries does not perform well. Also, “IN” operator also not good when looking for performance. So, I would try changing your query as below:

since test_name is used in filtering, creating index on text_name will help improving the performance. Also, index on latest_date (but usually indexes on datetime column won’t make big difference but okay to consider. if its just date column then yes, you will see some improvement). I am assuming geotype_id would be primary key and/or foreign keys in respective tables. If that is not the case, you will need indexes on them as well.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement