mysql 模糊查询语句比较(LIKE、instr、locate、find_in_set、position)
来源:互联网 发布:什么是网络架构 编辑:程序博客网 时间:2024/04/30 07:01
- 你是否一直在寻找比MySQL的LIKE语句更高效的方法的,下面我就为你介绍几种。
LIKE语句
SELECT `column` FROM `table` where `condition` like`%keyword%'
事实上,可以使用 locate(position) 和 instr这两个函数来代替
LOCATE语句
SELECT `column` from `table` where locate(‘keyword’,`condition`)>0
或是 locate 的別名 position
POSITION语句
SELECT `column` from `table` where position(‘keyword’ IN`condition`)
或是
INSTR语句
SELECT `column` from `table` where instr(`condition`, ‘keyword’)>0
locate、position 和 instr 的差別只是参数的位置不同,同时locate多一个起始位置的参数外,两者是一样的。
mysql> SELECT LOCATE(‘bar’, ‘foobarbar’,5);
-> 7
速度上这三个比用 like 稍快了一点。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
还要给大家介绍一个新成员,那就是find_in_set find_in_set(str1,str2) 函数:返回str2中str1所在的位置索引,其中str2必须以","分割开。 表: 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语句 mysql> select * from test where find_in_set('name1',name); +----+------------+ | id | name | +----+------------+ | 1 | name1,nam2 | | 2 | name1 | +----+------------+ 2 rows in set (0.02 sec)
0 0
- mysql 模糊查询语句比较(LIKE、instr、locate、find_in_set、position)
- SQL之查询函数LOCATE、POSITION、INSTR、FIND_IN_SET、IN、LIKE
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate/position/instr/find_in_set
- MySQL比like语句更高效的写法locate、position、instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL:比like语句更高效的写法locate position instr find_in_set(2014-05-07 17:40:04)
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- mysql语句备忘
- linux 中特殊符号用法详解
- java-IO流8(序列流)
- 每周荐书:机器学习、Spring MVC、Android(评论送书)
- 虚函数和纯虚函数
- mysql 模糊查询语句比较(LIKE、instr、locate、find_in_set、position)
- linux常用命令
- List/Map/Json
- Linux命令—find命令用法小结
- Struts2 异常处理
- 欢迎使用CSDN-markdown编辑器
- android matrix 最全方法详解与进阶(完整篇)
- HDU 5976 Detachment(逆元)+逆元总结
- CSS中常用字体