Difference between LIKE and = in MYSQL?

= in SQL does exact matching.

LIKE does wildcard matching, using ‘%’ as the multi-character match symbol and ‘_’ as the single-character match symbol. ‘\’ is the default escape character.

foobar="$foo" and foobar LIKE '$foo' will behave the same, because neither string contains a wildcard.

foobar LIKE '%foo' will match anything ending in ‘foo’.

LIKE also has an ESCAPE clause so you can set an escape character. This will let you match literal ‘%’ or ‘_’ within the string. You can also do NOT LIKE.

The MySQL site has documentation on the LIKE operator. The syntax is

expression [NOT] LIKE pattern [ESCAPE 'escape']

Leave a Comment