MySQL OR Operator

MySQL OR Operator is one of the Logical Operators. Generally, we use this one in the WHERE Clause to apply multiple filters on the records returned by the SELECT Statement. This OR operator returns the result as:

  • 1, if all operands are not nulls, and any of the one operands is non-zero.
  • 0, if all the operands are not nulls, and all of them are zeros.
  • NULL, If one of the operands is NULL, and the remaining operands are zeros, otherwise 1.

Let us see how to use the Logical Operator OR in the WHERE clause to filter the data. To explain it, we are going to use the below-shown data.

Customer Table Records 0

MySQL OR Operator Command prompt

In this OR example, we pass Ones, Zeros, and Null values with a different combination. This example helps you to understand the Truth table behind the OR Operator.

SELECT 0 OR 0;

SELECT 1 OR 1;

SELECT 1 OR 0;

SELECT 1 OR NULL;

SELECT 0 OR NULL;

SELECT NULL OR NULL;
Example 1

OR Operator Example

The OR test multiple conditions in the WHERE Clause. If either one of the conditions is TRUE, then it displays the records.

USE company;
SELECT CustID,
		First_Name, Last_Name,
        Education, Profession,
        Yearly_Income, Sales
FROM customers
WHERE Education = 'High School'
   OR Profession = 'Developer';

The above SELECT Statement retrieves all the Customers present in the MySQL Customers table whose Education is High School or Profession as Developer (WHERE Clause).

Example 2

You can also use MySQL OR operator between three or 4 conditions. Let us apply it between the three conditions.

USE company;
SELECT CustID,
		First_Name, Last_Name,
        Education, Profession,
        Yearly_Income, Sales
FROM customers
WHERE Education = 'High School'
	OR Profession = 'Developer'
    OR Yearly_Income > 90000;

The above statement retrieves Customers from the Customer table whose Education is High School, or Profession as a Developer, or Yearly Income is greater than 90000.

MySQL OR Operator Example 3