This tutorial explains how to use the MySQL OR condition with syntax and examples.
The MySQL OR Condition is used to test two or more conditions where records are returned when any one of the conditions are met. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the OR Condition in MySQL is:
Parameters or Arguments
condition1, condition2, ... condition_n
Any of the conditions that must be met for the records to be selected.
The MySQL OR condition allows you to test 2 or more conditions.
The MySQL OR condition requires that any of the conditions (ie: condition1, condition2, condition_n) be must be met for the record to be included in the result set.
Example - With SELECT Statement
The first MySQL OR condition example that we'll take a look at involves a SELECT statement with 2 conditions:
This MySQL OR condition example would return all customers that reside in either the state of California or have a contact_id less than 1000. Because the * is used in the SELECT statement, all fields from the contacts table would appear in the result set.
Example - With SELECT Statement (3 conditions)
The next MySQL OR example looks at a SELECT statement with 3 conditions. If any of these conditions is met, the record will be included in the result set.
This MySQL OR condition example would return all supplier_id and supplier_name values where the supplier_name is either Microsoft, the state is Florida, or offices is greater than 10.