If you have been looking for a more efficient method than the MySQL like statement, let me introduce you to a few.
Like statement
SELECT ' column ' from ' table ' where ' condition ' like '%keyword% '
In fact, you can useLocate (position) and InStrThese two functions take the place of
Locate statements
SELECT ' column ' from ' Table ' where locate (' keyword ', ' condition ') >0
or locate's name position.
position Statements
SELECT ' column ' from ' table ' where position (' keyword ' in ' condition ')
Or
InStr Statements
SELECT ' column ' from ' Table ' where InStr (' condition ', ' keyword ') >0
The difference between locate, position, and InStr is just the same as the parameter location, and the parameter of locate more than one starting position.
mysql> SELECT LOCATE (' Bar ', ' Foobarbar ', 5);
7
The speed of these three is a little bit faster than using like.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Gorgeous split-line ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and we're going to introduce you to a new member, that's find_in_set.
find_in_set (STR1,STR2) function: Returns the position index where STR2 is located in str1, where str2 must be separated by ",". Table:mysql> SELECT * FROM region;+----+-------------+| ID | name |+----+-------------+| 1 | name1,nam2 | | 2 | name1 | | 3 | Name3 | | 4 | name2,name4 | | 5 | name3,name5 |+----+-------------+5 rows in Set (0.00 sec) find_in_set statement MySQL > select * from Test where find_in_set (' name1 ', name); +----+------------+| ID | Name |+----+------------+| 1 | name1,nam2 | | 2 , | name1 |+----+------------+2 rows in Set (0.02 sec) Thank you for your attention websites blog.
More efficient writing in MySQL than like statements locate position InStr Find_in_set