views:

2773

answers:

3

First off, I recognize the differences between the two:
- Like makes available the wildcards % and _
- significant trailing whitespace
- colation issues

All other things being equal, for an exact string match which is more efficient:

SELECT field WHERE 'a' = 'a';

Or:

SELECT field WHERE 'a' LIKE 'a';

Or: Is the difference so insignificant that it doesn't matter?

+3  A: 

I would say that the = comparator would be faster. The lexical doesn't send the comparison to another lexical system to do general matches. Instead the engine is able to just match or move on. Our db at work has millions of rows and an = is always faster.

Suroot
+2  A: 

This has previously been covered here on stackoverflow.

http://stackoverflow.com/questions/543580/equals-vs-like

I hope this helps.

Thanks, I searched for this before posting but didn't see it somehow.
mluebke
What you can do is use google to search stackoverflow for you. It can sometimes come back with more relevant results.
A: 

In a decent DBMS (e.g., DB2 :-), the DB engine would recognize that there were no wildcard characters in the string and implicitly turn it into an "=" version. So, you'd only get a small performance hit at the start, usually negligible for any decent-sized query.

paxdiablo