
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Working with MySQL WHERE.. OR query with multiple OR usage. Is there an alternative?
Yes, an alternative for MySQL “WHERE.. OR” is using REGEXP.
Let us first create a table −
mysql> create table DemoTable684(EmployeeInformation text); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
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)
Display all records from the table using select statement −
mysql> select *from DemoTable684;
This will produce the following output −
+---------------------+ | EmployeeInformation | +---------------------+ | John 21 Google | | Carol 23 Amazon | | Carol 26 Flipkart | | David 29 Microsoft | +---------------------+ 4 rows in set (0.00 sec)
Following is the query for implementing MySQL where...OR using REGEXP −
mysql> select *from DemoTable684 where EmployeeInformation REGEXP '(David|29|Microsoft)';
This will produce the following output −
+---------------------+ | EmployeeInformation | +---------------------+ | David 29 Microsoft | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- Implement MySQL query using multiple OR statements. Any optimal alternative?
- MySQL select query with multiple WHERE?
- MySQL query to return multiple row records with AND & OR operator
- MySQL query with OR & AND conditions
- Fetch multiple documents in MongoDB query with OR condition?
- Multiple WHERE with LIMIT in MySQL?
- MongoDB query to get documents with multiple conditions set in $or?
- How to work with “!=” or “not equals” in MySQL WHERE?
- Implement WHERE IN vs OR in MySQL with similar example
- MongoDB query with an 'or' condition?\n
- Working with WHERE IN() in a MySQL Stored Procedure
- Is there any alternative for CONCAT() in MySQL?
- Update with multiple values in MySQL WHERE clause
- Can we use WHERE, AND & OR in a single MySQL query?
- Select multiple values with MongoDB OR operator

Advertisements