What is the difference between LIKE '%...%' and IN () in MySQL?

  • 3
    ... are there any similarities? Well, except that both of them are statements in MySQL. - D-side
  • @ D-side Sometimes IN can be replaced with an inverted LIKE . - Alex78191

1 answer 1

In short, LIKE - search in string, IN in list

LIKE - performs a simple pattern matching. There can be service symbols in the pattern % - matches any number (including zero) of characters, _ - any one character

For example:

 'Тестовая строка' LIKE '%строка%' 

will give 1 which means that the left argument matches the pattern specified in the right argument

IN checks for the presence of a value (left argument) in the list (right argument)

For example:

 'один' IN ('один', 'два', 'три') 

will give 1 which means that the left argument is contained in the list in brackets

  • one
    I think such questions need to be sent to read the SQL help - nick_n_a
  • @nick_n_a Unfortunately, there are a lot of such questions. And not everyone can read English. On this issue, you can certainly find the answer in Russian, but the latest MySQL documentation is only in English. Some are scared away (and some just lazy :)) - tutankhamun
  • You can read the help is not necessarily MySQL. - Alex78191
  • one
    Mysql 4 was translated a few years ago, since then it was at this point that nothing has changed (it's ANSI 92 SQL). But the desire to read in English is not enough ... but there is a lot of laziness. - AK