如何使用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)
以上是 如何使用MySQL LIKE提取具有多个值的字段? 的全部内容, 来源链接: utcz.com/z/327235.html