Difference between LIKE and = in MYSQL?

后端 未结 12 1925

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 08:53

    I think in term of speed = is faster than LIKE. As stated, = does an exact match and LIKE can use a wildcard if needed.

    I always use = sign whenever I know the values of something. For example

    select * from state where state='PA'
    

    Then for likes I use things like:

    select * from person where first_name like 'blah%' and last_name like 'blah%'
    

    If you use Oracle Developers Tool, you can test it with Explain to determine the impact on the database.

提交回复
热议问题