为此,可以将WHERE子句与多个LIKE一起使用。让我们首先创建一个表-
create table DemoTable1536 -> ( -> Sentence text -> );
使用插入命令在表中插入一些记录-
insert into DemoTable1536 values('I like MySQL database.'); insert into DemoTable1536 values('Java is an Object Oriented Programming Language'); insert into DemoTable1536 values('I only like data structure'); insert into DemoTable1536 values('MongoDB is NoSQL database');
使用select语句显示表中的所有记录-
select * from DemoTable1536;
这将产生以下输出-
+--------------------------------------------------+ | Sentence | +--------------------------------------------------+ | I like MySQL database. | | Java is an Object Oriented Programming Language | | I only like data structure | | MongoDB is NoSQL database | +--------------------------------------------------+ 4 rows in set (0.00 sec)
以下是查询多个单词的查询-
select * from DemoTable1536 -> where ( Sentence like '%like%') or (Sentence like '%database%') or (Sentence like '%data%');
这将产生以下输出-
+----------------------------+ | Sentence | +----------------------------+ | I like MySQL database. | | I only like data structure | | MongoDB is NoSQL database | +----------------------------+ 3 rows in set (0.00 sec)