Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speedy Search Question

Status
Not open for further replies.

Brit

Programmer
May 15, 2001
15
US
If you are doing a search against several columns in the database (product category, product description, product short description) and using 'LIKE', is it faster to search each field or a concatenation of all the fields?

For example
select ...
from ...
where columnA like '%abc%'
or columnB like '%abc%'
or columnC like '%abc%'

versus

select ...
from ...
where (columnA + coulumnB + columnC) like '%abc%'

My guess is the conactenation takes too much time


 
I think you're right that the concatenation would add time to the query. However there's a more serious problem - the two queries aren't identical. The concatenation search will match all rows returned by the first query, but will also produce spurious matches. For example, suppose

columnA = 'scarab'
columnB = 'caliph'
columnC = 'delphi'

Then columnA + columnB + columnC = scarabcaliphdelphi'

and that matches "like '%abc%'" because of the 'ab' at the end of scarab being concatenated right before the 'c' in caliph.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top