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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIKE operator

Status
Not open for further replies.

StephenLeach

Programmer
Joined
Aug 20, 2003
Messages
8
Location
US
In a SELECT statement I have a condition along the lines of columnName LIKE '%'.

I have noticed that this gives different results to '%' LIKE columnName.

Why is this? I would have thought that the LIKE operator would behave as the = operator, as in a=b is equivalent to saying b=a.

Does anyone know where I can can more information on this subject?

Thanks in advance

Stephen
 
Just relised the answer myself...

a LIKE b is looking for pattern b inside string a

where as

b LIKE a is looking for pattern a inside string b


Sorry for opsting a question and then answering it five minutes later...

Stephen
 
Just so you know, using like % makes your query run without the use of indexes which will slow it down. Try not to use a wildcard as the first character for a search unless it is absolutely necessary.
 
True but like
Code:
"H%"
will be fast as it will do a ranged scan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top