Hi Joshua, all!
Am Di, den 08.02.2005 schrieb Joshua Beall um 17:18: > 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? Semantically, they are equivalent and must return the same results. But 'LIKE' may/will cause the server to take a different execution path than '=', one in which regular expressions are accepted. I will not make a specific claim about a specific system / version, let alone predict numbers, but I sure expect that the '=' predicate will be evaluated faster than 'LIKE', so the first statement will yield a better performance. Should it be slower, you would surely have found a bug ;-) In December, we had someone using 'LIKE' for numbers. It worked, but the performance gain from switching to '=' was enormous for him. (My guess is that 'LIKE' forced the values to be converted into strings first ... ) So: If possible, use '=' and spare 'LIKE' for those cases where it is really needed. HTH, Joerg -- Joerg Bruehe, Senior Production Engineer MySQL AB, www.mysql.com Office: (+49 30) 417 01 487 Are you MySQL certified? www.mysql.com/certification -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]