Optimising the SQL query
Optimising a query of this size can seem a very daunting task. In reality, there are a handful of important points you can keep in mind to make optimisation decisions to make your query run faster.
SQL Wildcards
In general, leading wildcards in SQL queries will force a full table scan (an extremely slow form of data retrieval that ignores indexes). Trailing wildcards aren't as bad, but you should only use them when you have no idea what might come after the wildcard; if there is a known list of possible values, using IN or NOT IN is probably better.
Inefficient Table Joins
Text
Inefficient subqueries
Text