How to search any part of the string with mysql

Asked

Viewed 3,300 times

2

Hello, I use this way to search in Mysql string%, but in a phrase "test a two three" if I use ste% it will not return the phrase, as I could search whether it contains within the sentence?

  • 3

    Try to use %ste%

  • What is the intention to put the % at the end of the search string, if what varies in your example is the beginning? The % is the joker, if you want to find things that change on both sides, you have to on both sides, as @Maurivan said. In your case, if you look for "test%" you will find, because it starts with "tes". If you look for "%rês" too, because it ends with "rês" the phrase. Note the difference in position of the %

  • @Bacco But for example, in a string "Wolverine", I want when searching veri already result in Wolverine, how can I do that ??

  • Lucascarezia exactly what @Maurivan already said, campo LIKE "%veri%" one % before and one % after

1 answer

1


Since what you want doesn’t start with Ste no use you performing a select like this ste% because it will return to you everything that begins with Ste followed by anything.

So I can take everything that contains Ste your select will have to have %ste%

select coluna from tabela where coluna like %ste%

Browser other questions tagged

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