为此,您可以使用LIKE子句。让我们首先创建一个表-mysql> create table DemoTable
-> (
-> ClientName varchar(100)
-> );
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values('John Smith');
mysql> insert into DemoTable values('Smith John');
mysql> insert into DemoTable values('Jone Deo');
mysql> insert into DemoTable values('Deo Jone');
mysql> insert into DemoTable values('Chris Brown');
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
输出结果
这将产生以下输出-+-------------+
| ClientName |
+-------------+
| John Smith |
| Smith John |
| Jone Deo |
| Deo Jone |
| Chris Brown |
+-------------+
5 rows in set (0.00 sec)
以下是在单个MySQL查询中获取记录“ Jone Deo”或“ Deo Jone”的查询-mysql> select *from DemoTable
-> where ClientName
-> LIKE
-> (SELECT SUBSTRING_INDEX("%Jone% %Deo%", " ", -1))
-> or
-> (SELECT SUBSTRING_INDEX("%Deo% %Jone%", " ", 1));
输出结果
这将产生以下输出-+------------+
| ClientName |
+------------+
| Jone Deo |
| Deo Jone |
+------------+
2 rows in set (0.00 sec)