zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

MySQL:模糊查询LIKE、REGEXP、IN

mysql 查询 in 模糊 like REGEXP
2023-09-27 14:24:15 时间

1、[NOT] LIKE

百分号(%):任意个或多个字符
下划线(_):任意单个字符

SELECT * FROM students WHERE name LIke '王%;

2、[NOT] REGEXP

字符
. 任何单个的字符
[…]在方括号内的任何字符
^ 匹配开始
$ 匹配结尾
数量
* 零个或多个在它前面的字符

SELECT * FROM students WHERE name REGEXP "^王";

3、in查询
in 后面可以是多个值

select * from students where name in ("王小二","李四");

4、like contact模糊查询

select * from students where name like contact("%", "王小二", "%");

参考
mysql模糊匹配查询like,regexp,in