如何使用MySQL LIKE提取具有多个值的字段?
要获取具有多个值的字段,请在MySQL中将LIKE与OR配合使用-
select *from yourTableName where yourColumnName like ‘%AnyStringValue’ or yourColumnName like ‘%AnyStringValue’ or yourColumnName like ‘%AnyStringValue’ ……...N;
您可以借助表格来了解-
create table LikeDemo
−> (
−> Hobby varchar(200)
−> );借助insert命令将一些记录插入表中。在表中插入记录的查询如下-
insert into LikeDemo values('Reading Book');
insert into LikeDemo values('Playing Cricket Match');
insert into LikeDemo values('Playing Hockey Match');
insert into LikeDemo values('Reading Novel');
insert into LikeDemo values('Swimming');
Displaying all records with the help of select statement. The query is as follows:
select *from LikeDemo;以下是输出-
+-----------------------+ | Hobby | +-----------------------+ | Reading Book | | Playing Cricket Match | | Playing Hockey Match | | Reading Novel | | Swimming | +-----------------------+ 5 rows in set (0.00 sec)
使用LIKE获取具有多个值的字段的查询如下-
select *from LikeDemo where Hobby like '%Cricket%' or Hobby like '%Reading%';
以下是输出-
+-----------------------+ | Hobby | +-----------------------+ | Reading Book | | Playing Cricket Match | | Reading Novel | +-----------------------+ 3 rows in set (0.00 sec)
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短