使用 MySQL WHERE.. OR 查詢並帶有多個 OR 用法。是否有替代方案?
是的,可以使用 REGEXP 作為 MySQL “WHERE.. OR” 的替代方案。
讓我們首先建立一個表 −
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)
Advertisements
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP