我们可以在单个MySQL查询中实现“ LIKE”和“ IN”吗?
为了提高效率,请将正则表达式用于同一任务。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Name varchar(30) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John');
mysql> insert into DemoTable values('Chris');
mysql> insert into DemoTable values('Robert');
mysql> insert into DemoTable values('David');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+ | Name | +--------+ | John | | Chris | | Robert | | David | +--------+ 4 rows in set (0.00 sec)
这是为LIKE和IN替代实现REGEXP的查询-
mysql> select *from DemoTable where Name REGEXP 'John|Robert|David';
这将产生以下输出-
+--------+ | Name | +--------+ | John | | Robert | | David | +--------+ 3 rows in set (0.11 sec)
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短