Difference between LIKE and = in MYSQL?

后端 未结 12 1913

What\'s the difference between

SELECT foo FROM bar WHERE foobar=\'$foo\'

AND

SELECT foo FROM bar WHERE foobar LIKE\'$foo\'         


        
12条回答
  •  萌比男神i
    2020-11-29 09:17

    In your example, they are semantically equal and should return the same output.

    However, LIKE will give you the ability of pattern matching with wildcards.

    You should also note that = might give you a performance boost on some systems, so if you are for instance, searching for an exakt number, = would be the prefered method.

提交回复
热议问题