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
One, locate statements
SELECT ' column ' from ' Table ' where locate (' keyword ', ' condition ') >0
second, or locate's name position
Position statements
SELECT ' column ' from ' table ' where position (' keyword ' in ' condition ')
Third, InStr statement
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Four, we also want to introduce a new member, that is Find_in_set
find_in_set (STR1,STR2) function: Returns the position index where str2 is in str1, where str2 must be split with ",".
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)
v. Of course, there is also a full-text index of MySQL
Full-text index: http://dev.mysql.com/doc/ refman/5.6/en/fulltext-search.html
MySQL is more efficient than a like statement locate position InStr Find_in_set