Difference between LIKE and = in MYSQL?

后端 未结 12 1923

What\'s the difference between

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

AND

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


        
12条回答
  •  野性不改
    2020-11-29 09:06

    I found an important difference between LIKE and equal sign = !

    Example: I have a table with a field "ID" (type: int(20) ) and a record that contains the value "123456789"

    If I do:

    SELECT ID FROM example WHERE ID = '123456789-100'
    

    Record with ID = '123456789' is found (is an incorrect result)

    If I do:

    SELECT ID FROM example WHERE ID LIKE '123456789-100'
    

    No record is found (this is correct)

    So, at least for INTEGER-fields it seems an important difference...

提交回复
热议问题