| Hi All,
|
| From what I understand the LIKE keyword allows you to do things like
include
| wildcards and match against regular expressions.
|
| But I have a question: is there any difference between the following?
|
| SELECT lname, fname FROM contacts WHERE lname = 'smith';
| SELECT lname, fname FROM contacts WHERE lname LIKE 'smith';
|
| I'm having difficulty figuring out the difference between these two
queries,
| if there is any.  Can someone clarify?
|
| Sincerely,
|   -Josh


As long the expression on the right hand side of the equal sign uses no
wildcard characters (% or _), the two WHERE conditions you've written are
functionally equivalent; they should get the same rows for their respective
result sets.

However, there *may* be a performance difference between the two. I don't
know if MySQL treats the two differently in terms of choosing an access path
but DB2 will normally choose a better access path for '=' than 'LIKE',
regardless (I think) of whether the LIKE expression contains wildcards. My
gut hunch is that if your LIKE expression is going to contain no wildcards,
you should probably write it as an '=' simply because it is likely to
perform better.

If anyone reading this is knowledgeable on MySQL performance, please jump in
and correct me if I'm wrong.

Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to