What real difference between the '=' and LIKE?

3

By doing another test (rs) on a database that I have in MySQL, I realized that:

SELECT * From client WHERE uuid = '1kvsg4oracxq'

returned the same result as:

SELECT * From client WHERE uuid LIKE '1kvsg4oracxq'

What exactly is the difference between the = and LIKE operator? In which situation is it preferable to use one or the other?

    
asked by anonymous 12.06.2017 / 18:15

1 answer

7

Equal = looks for equivalence characters per character, must be exactly the same.

While LIKE looks for "something like", that is, content that has searched text in a part of where (column (s)) you are looking for. Usually the % symbol is used to indicate where you can have wildcard characters, where you can have anything else.

The use of '1kvsg4oracxq%' still usually allows the use of an index, but in any other logar it can prevent the indexed consumption and have poor performance, or even tragic (depends, has to measure, not always bad) . In these cases use a inverted index for full text search may be more appropriate.

The _ is also used for only one wildcard character. Some syntaxes allow other ways to express what you can use.

Without % the result is to be the same. But there is one exception, which is about the space at the end. = normally ignores them. If you do not use % in LIKE , they will not be ignored.

    
12.06.2017 / 18:27