What is the real difference between the operator '=' and LIKE?

Asked

Viewed 1,722 times

3

Doing another test (rs) in a database 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 real difference between the operator = and LIKE? In which situation it is preferable to use one or the other?

  • Rela: https://answall.com/q/191573/101

1 answer

7


The same = search for equivalence character by character, has to be exactly equal.

Already the LIKE looks for "something like", ie content that has the text searched in a part of where (column(s)) you are looking for. In general the symbol is used % to indicate where there may be wildcard characters, where there may be anything else.

The use of '1kvsg4oracxq%' still allows the use of an index, but anywhere else it can disable the indexed consumption and have poor performance, or even tragic (depends, has to measure, is not always bad). In such 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 % the result is to be the same. But there is an exception, which is about the spaces at the end. The = usually ignores them. If not using % in the LIKE, they will not be ignored.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.