使用 MySQL WHERE.. OR 查询进行多次 OR 操作。有其他替代方法吗?
mysqlmysqli database更新于 2025/10/21 15:40:17
是的,MySQL "WHERE.. OR" 的替代方法是使用 REGEXP。
首先我们创建一个表 −
mysql> create table DemoTable684(EmployeeInformation text); Query OK, 0 rows affected (0.68 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable684 values('John 21 Google');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable684 values('Carol 23 Amazon');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable684 values('Carol 26 Flipkart');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable684 values('David 29 Microsoft');
Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable684;
这将产生以下输出 −
+---------------------+ | EmployeeInformation | +---------------------+ | John 21 Google | | Carol 23 Amazon | | Carol 26 Flipkart | | David 29 Microsoft | +---------------------+ 4 rows in set (0.00 sec)
以下是使用 REGEXP 实现 MySQL where...OR 的查询 −
mysql> select *from DemoTable684 where EmployeeInformation REGEXP '(David|29|Microsoft)';
这将产生以下输出 −
+---------------------+ | EmployeeInformation | +---------------------+ | David 29 Microsoft | +---------------------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

