1
select top 10 productName 
from Products 
where productDetails like '%something%' 
group by productName
order by productName asc

What should i do/change on my query to improve performance?

Adem Büyük
  • 563
  • 7
  • 15
  • Using `LIKE '%something%'` makes sure SQL Server cannot use any kind of index - that's what's killing performance in your query! Avoid this to improve your search speed – marc_s Nov 02 '15 at 14:21

1 Answers1

2

Having a query with a clause, <column> like '%<anything>' will cause a table scan to check every single row to see if it matches the clause. Depending on your choice of RDBMS, and your exact requirements, you could look into full text indexing, or if your queries could be rewritten to be <column> like '<something>%', then the query will be able to use indexes on the column.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166