MySQL OR Operator
The OR operator in MySQL is used to combine multiple conditions in a SELECT, INSERT, UPDATE, or DELETE statement, and returns true if any of the conditions are true.
The syntax for using the OR operator in a SELECT statement is as follows:
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR ...;
Here’s an example:
SELECT * FROM customers
WHERE city = 'New York' OR city = 'London';
Table structure Used for Example explanation
+------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| id | int(11) unsigned | NO | PRI | NULL | |
| name | varchar(255) | NO | UNI | NULL | |
| code | varchar(3) | NO | UNI | NULL | |
| population | int(11) | NO | | NULL | |
| currency_code | varchar(3) | YES | | NULL | |
| capital | varchar(255) | YES | | NULL | |
| area | double | YES | | NULL | |
| time_zone | varchar(255) | YES | | NULL | |
| languages | varchar(255) | YES | | NULL | |
| created_at | datetime | NO | | NULL | |
| updated_at | datetime | NO | | NULL | |
+------------------+------------------+------+-----+---------+------
Example for MySQL OR Operator
SELECT Name, Population FROM Country WHERE Population > 100000000 OR (Continent = 'Asia' );
Output of Above Example
+———————-+————+
| Name | Population |
+———————-+————+
| Afghanistan | 22720000 |
| United Arab Emirates | 2441000 |
| Armenia | 3520000 |
| Azerbaijan | 7734000 |
| Bahrain | 617000 |
| Bangladesh | 129155000 |
| Bhutan | 2124000 |
| Brazil | 170115000 |
| Brunei | 328000 |
| Philippines | 75967000 |
| Georgia | 4968000 |
| Hong Kong | 6782000 |
| Indonesia | 212107000 |
| India | 1013662000 |
| Iraq | 23115000 |
| Iran | 67702000 |
| Israel | 6217000 |
| East Timor | 885000 |
| Japan | 126714000 |
| Yemen | 18112000 |
| Jordan | 5083000 |